Mega Code Archive

 
Categories / XML Tutorial / XSLT StyleSheet
 

Sort order=descending

File: Data.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="Transform.xslt" type="text/xsl"?> <europe>   <state>Belgium</state>   <state>Germany</state>   <state>Finland</state>   <state>Greece</state>   <state>Ireland</state>   <state>Luxembourg</state>   <state>Switzerland</state> </europe> File: Transform.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <xsl:output method="text" />   <xsl:template match="europe">     <xsl:apply-templates select="state">       <xsl:sort order="descending" />     </xsl:apply-templates>     <xsl:text>Number of European States: </xsl:text>     <xsl:value-of select="count(state)" />     <xsl:text>&#10;</xsl:text>   </xsl:template>   <xsl:template match="state">     <xsl:text> - </xsl:text>     <xsl:apply-templates />     <xsl:text>&#10;</xsl:text>   </xsl:template> </xsl:stylesheet> Output:  - Switzerland  - Luxembourg  - Ireland  - Greece  - Germany  - Finland  - Belgium Number of European States: 7