posted 16 years ago
I am using XSL to convert an XML file to a csv file.
The XML file in the format below:
<file>
<record>
<name>Johnny</name>
<age>32</age>
</record>
<record>
<name>Jimmy</name>
<age>5</age>
</record>
<record>
<name>Baby Moon</name>
<age>1</age>
</record>
<record>
<name>Lisa</name>
<age>25</age>
</record>
</file>
My xsl file should be implemented such that all records where age <20 are ignored.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="file/record">
<xsl:if test="age > 20">
<xsl:value-of select="position()"/>
<xsl:value-of select="name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="age"/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I need to keep track of the records that have been picked and keep a sequence going. Following is the expected result.
1,Johnny,32
2,Lisa,25
but I am getting
1,Johnny,32
4,Lisa,25
How can I fix this?
Thanks!
[ May 13, 2008: Message edited by: Cindy Jones ]