i’m transforming all xml elements into xhtml <div> tags using a recursive template match.
basically, i wish to turn the element name() into a class name, ie . <div class="name()">value</div>
i used the following:
<body>
<xsl:apply-templates />
</body>
<xsl:template match="*">
<div class="{name()}"><xsl:value-of select="."/>
<xsl:apply-templates select="*"/>
</div>
</xsl:template>
it works quite well, except it plucks out the values on parent tags.
for example, this xml
<TotalPayments>
<Amount>26.96</Amount>
<TaxableAmount>26.96</TaxableAmount>
<TaxAmount>0.00</TaxAmount>
<ShippingAmount>0.00</ShippingAmount>
</TotalPayments>
turns into:
<div class="TotalPayments">
26.96
26.96
0.00
0.00
<div class="Amount">26.96</div>
<div class="TaxableAmount">26.96</div>
<div class="TaxAmount">0.00</div>
<div class="ShippingAmount">0.00</div>
</div>
and i only want
<div class="TotalPayments">
<div class="Amount">26.96</div>
<div class="TaxableAmount">26.96</div>
<div class="TaxAmount">0.00</div>
<div class="ShippingAmount">0.00</div>
</div>
And it gets worse and worse up the tree. the root has all that too.
so should i do a test or can one select only certain types.
i also tried matching
* | text()
* | node()
thanks.
Simply remove the
<xsl:value-of select="."/>and then change the<xsl:apply-templates select="*"/>to<xsl:apply-templates/>. That way the default template for text node children will output them (and the elements children are processed the same as before).