I want to genereate a csv file form an XML as shown below, and the content
of csv are as follows
<DATE>,<first ATOM/NAME>,<second ATOM/NAME>
I am able to select first and the second NAME element, but the problem is
that when number of instances of <NAME> is<2 I want the output to be
<DATE>,, (at least two comma)
But since the elements are not present so the rule does not execute and i
don't get any comma in the output.csv
Please suggest what should be done.
The files i used are as follows.
*************** Input XML
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="xml.xsl"?>
<PERIODIC_TABLE>
<DATE>12/29/2005</DATE>
<ATOMS>
<NAME>Hydrogen</NAME>
</ATOMS>
<ATOMS>
<NAME>Helium</NAME>
<NAME>Neon</NAME>
</ATOMS>
<ATOMS>
<NAME>Carbon</NAME>
<NAME>Oxygen</NAME>
<NAME>Copper</NAME>
<NAME>Iron</NAME>
<NAME>Argon</NAME>
</ATOMS>
<ATOMS></ATOMS>
</PERIODIC_TABLE>
********************* The XSL
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="PERIODIC_TABLE">
<xsl:apply-templates select="ATOMS"/>
</xsl:template>
<xsl:template match="ATOMS">
<xsl:apply-templates select="NAME"/><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="NAME">
<xsl:if test="position()<3"><xsl:value-of select="self::NAME"/>,</xsl:if>
</xsl:template>
</xsl:stylesheet>