I need help with a small example, so that I can understand xsl:sort
better.
My XML data looks like:
<NewTerms>
<newTerm ID="3">Zebra</newTerm>
<newTerm ID="11">Horse</newTerm>
<newTerm ID="1">Cat</newTerm>
<newTerm ID="90">Lion</newTerm>
<newTerm ID="62">Jaguar</newTerm>
<newTerm ID="30">Cheetah</newTerm>
<newTerm ID="55">Deer</newTerm>
<newTerm ID="45">Buffalo</newTerm>
<newTerm ID="15">Dog</newTerm>
</NewTerms ID="10">
and I want to sort them according to the ID
attribute. The XSL that I have is not working:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="@*|node()[not(preceding::node()=.)]">
<xsl:copy>
<xsl:apply-templates select="@*|node()[not(preceding::node()=.)]">
<xsl:sort select="./@ID"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I don't know how the xsl:sort
function works. Help me through this example to get a better understanding of it.