I'm applying xslt transformation to an xml file and some children
nodes' attributes aren't working.
The relevant xml file section looks like this:
<table2_ColumnGroup2_Collection>
<table2_ColumnGroup2>
<table2_ColumnGroup1_Collection>
<table2_ColumnGroup1 Test="Blood 1">
<Cell Result="16.9" />
</table2_ColumnGroup1>
<table2_ColumnGroup1 Test="Blood2">
<Cell Result="16.8" />
</table2_ColumnGroup1>
</table2_ColumnGroup1_Collection>
</table2_ColumnGroup2>
<table2_ColumnGroup2>
<table2_ColumnGroup1_Collection>
<table2_ColumnGroup1 Test="Blood 3">
<Cell Result="15.4" />
</table2_ColumnGroup1>
</table2_ColumnGroup1_Collection>
</table2_ColumnGroup2>
The relevant code in the xslt file is as follows: A line to apply the
template to each value of the @Test attribute:
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 1]"/>
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 2]"/>
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 3]"/>
and then the template that matches a node with the @Test attribute:
<xsl:template match="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test]">
<xsl:value-of select="@Test"/>
<xsl:value-of select="Cell[@Result]"/>
</xsl:template>
It does output the value of @Test ("Blood 1" "Blood 2" and "Blood 3")
but the value of the "Cell" node's @Result attributes aren't outputted
at all. I'd like them to print the numeric values (16.9, 16.8, 15.4).
Would you please help? Thanks in advance,
Rick
<xsl:value-of select="Cell[@Result]"/>
and it should be
<xsl:value-of select="Cell/@Result"/>
to get the value of the Result attribute.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XmlTest6.xsl"?>
<table>
<table2_ColumnGroup2_Collection>
<table2_ColumnGroup2>
<table2_ColumnGroup1_Collection>
<table2_ColumnGroup1 Test="Blood 1">
<Cell Result="16.9" />
</table2_ColumnGroup1>
<table2_ColumnGroup1 Test="Blood 2">
<Cell Result="16.8" />
</table2_ColumnGroup1>
</table2_ColumnGroup1_Collection>
</table2_ColumnGroup2>
<table2_ColumnGroup2>
<table2_ColumnGroup1_Collection>
<table2_ColumnGroup1 Test="Blood 3">
<Cell Result="15.4" />
</table2_ColumnGroup1>
</table2_ColumnGroup1_Collection>
</table2_ColumnGroup2>
</table2_ColumnGroup2_Collection>
</table>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<!-- myxslt XmlTest6.xml XmlTest6.xsl -->
<xsl:output method="xml"/>
<xsl:template match="/table">
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 1']"/>
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 2']"/>
<xsl:apply-templates select="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test='Blood 3']"/>
</xsl:template>
<xsl:template match="table2_ColumnGroup2_Collection/
table2_ColumnGroup2/table2_ColumnGroup1_Collection/
table2_ColumnGroup1[@Test]">
<xsl:value-of select="@Test"/>
<xsl:value-of select="Cell/@Result"/>
</xsl:template>
</xsl:stylesheet>
Gives: Blood 116.9Blood 216.8Blood 315.4