Paul Smith
Usenet Archive
- Joined
- Jan 7, 2000
- Messages
- 186
- Reaction score
- 0
Apologies, I am new to XSLT. I am having trouble with something that I would expect to be quite straightforward.
How do I leave XML tags as they are in a transformation? From the XML below, I want to apply a stylesheet such that the XML is exactly the same apart from the only <row> should be the first one from the XML below. I can output some text for position=1 but I can't output the original XML too. So the only thing I get in my whole output document is "Found it"!
Any help would be greatly appreciated.
Original XML:
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/> </tablemetadata> <columnmetadata> <columnmetadataitem name="COL1" description="Col 1" pos="2"/> <columnmetadataitem name="COL2" description="Col 2" pos="1"/> </columnmetadata> <othertag> <othertagitem name="Type" value="Something"/> <othertagitem name="Direction" value="ASC"/> </parameterdata> <data> <row> <dataitem name="COL1" value="ABC"/> <dataitem name="COL2" value="123"/> </row> <row> <dataitem name="COL1" value="DEF"/> <dataitem name="COL2" value="456"/> </row> </data> </xmlresults>
Required Output from XSL transformation (note the second <row> is missing):
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/> </tablemetadata> <columnmetadata> <columnmetadataitem name="COL1" description="Col 1" pos="2"/> <columnmetadataitem name="COL2" description="Col 2" pos="1"/> </columnmetadata> <othertag> <othertagitem name="Type" value="Something"/> <othertagitem name="Direction" value="ASC"/> </parameterdata> <data> <row> <dataitem name="COL1" value="ABC"/> <dataitem name="COL2" value="123"/> </row> </data> </xmlresults>
My XSL (for what it's worth):
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl
utput method="html" indent="yes"/>
<xsl:template match="data">
<xsl:for-each select="row">
<xsl:choose>
<xsl:when test="position = 1">
Found It
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
How do I leave XML tags as they are in a transformation? From the XML below, I want to apply a stylesheet such that the XML is exactly the same apart from the only <row> should be the first one from the XML below. I can output some text for position=1 but I can't output the original XML too. So the only thing I get in my whole output document is "Found it"!
Any help would be greatly appreciated.
Original XML:
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/> </tablemetadata> <columnmetadata> <columnmetadataitem name="COL1" description="Col 1" pos="2"/> <columnmetadataitem name="COL2" description="Col 2" pos="1"/> </columnmetadata> <othertag> <othertagitem name="Type" value="Something"/> <othertagitem name="Direction" value="ASC"/> </parameterdata> <data> <row> <dataitem name="COL1" value="ABC"/> <dataitem name="COL2" value="123"/> </row> <row> <dataitem name="COL1" value="DEF"/> <dataitem name="COL2" value="456"/> </row> </data> </xmlresults>
Required Output from XSL transformation (note the second <row> is missing):
<?xml version="1.0" encoding="UTF-8"?>
<xmlresults status="SDSUCCESS">
<tablemetadata>
<tablemetadataitem name="TABLE1" description="Table 1"/> </tablemetadata> <columnmetadata> <columnmetadataitem name="COL1" description="Col 1" pos="2"/> <columnmetadataitem name="COL2" description="Col 2" pos="1"/> </columnmetadata> <othertag> <othertagitem name="Type" value="Something"/> <othertagitem name="Direction" value="ASC"/> </parameterdata> <data> <row> <dataitem name="COL1" value="ABC"/> <dataitem name="COL2" value="123"/> </row> </data> </xmlresults>
My XSL (for what it's worth):
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl
<xsl:template match="data">
<xsl:for-each select="row">
<xsl:choose>
<xsl:when test="position = 1">
Found It
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>