File: Data.xml
<?xml version="1.0"?>
<list>
<title>Java</title>
<listitem>Item 1</listitem>
<listitem>Item 2</listitem>
<listitem>Item 3</listitem>
<listitem>Item 4</listitem>
<listitem>Item 5</listitem>
<listitem>Item 6</listitem>
<listitem>Item 7</listitem>
<listitem>Item 8</listitem>
</list>
File: Transform.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="newline">
<xsl:text></xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$newline"/>
<xsl:text>Here are the odd-numbered items from the list:</xsl:text>
<xsl:value-of select="$newline"/>
<xsl:for-each select="list/listitem">
<xsl:if test="(position() mod 2) = 1">
<xsl:number format="1. "/>
<xsl:value-of select="."/>
<xsl:value-of select="$newline"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:
Here are the odd-numbered items from the list:1. Item 13. Item 35. Item 57. Item 7
|