Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

XSLT Sorting (See related posts)


XML:
<addresses>
  <address>
    <name>Robert Jones</name>	
    <street>Cedar Park Way</street>
    <city>Atlanta</city>
    <postcode>30083</postcode>
  </address>
</addresses>


XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="addresses">
    <xsl:apply-templates>
      <xsl:sort select="name"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="address">
	<!-- Name -->
	<p ><strong><xsl:value-of select="name"/></strong> </p>

	<!--Address-->
	<xsl:variable name="street" select="street"/>
	<xsl:if test="string($street)">
		<p ><strong>Address<br/></strong>
		<xsl:value-of select="$street" /><br/>
		<xsl:value-of select="postcode"/>&#xa0;<xsl:value-of select="city"/>
		</p>
	</xsl:if>  
  </xsl:template>

</xsl:stylesheet>

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts