File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<province name="BigCity">
<city>city 1</city>
<city>city 2</city>
<city>city 3</city>
<city>city 4</city>
<city>city 5</city>
<city>city 6</city>
<city>city 7</city>
<city>city 8</city>
<city>city 9</city>
<city>city 10</city>
<city>city 11</city>
</province>
File: Transform.xslt
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="province">
<xsl:text>BigCity Cities</xsl:text>
<xsl:call-template name="nl">
<xsl:with-param name="nl" select="' '" />
</xsl:call-template>
<xsl:apply-templates select="city" />
</xsl:template>
<xsl:template match="city">
<xsl:text> -> </xsl:text>
<xsl:value-of select="." />
<xsl:call-template name="nl">
<xsl:with-param name="nl" select="' '" />
</xsl:call-template>
</xsl:template>
<xsl:template match="city[.='city 4']">
<xsl:text> -> </xsl:text>
<xsl:value-of select="." />
<xsl:call-template name="nl">
<xsl:with-param name="nl"
select="' (second largest city in the Yukon) '" />
</xsl:call-template>
</xsl:template>
<xsl:template match="city[.='city 11']">
<xsl:text> -> </xsl:text>
<xsl:value-of select="." />
<xsl:call-template name="nl">
<xsl:with-param name="nl"
select="' (largest city in the Yukon) '" />
</xsl:call-template>
</xsl:template>
<xsl:template name="nl">
<xsl:param name="nl" />
<xsl:value-of select="$nl" />
</xsl:template>
</xsl:stylesheet>
Output:
BigCity Cities
-> city 1
-> city 2
-> city 3
-> city 4 (second largest city in the Yukon)
-> city 5
-> city 6
-> city 7
-> city 8
-> city 9
-> city 10
-> city 11 (largest city in the Yukon)
|