In continuation to using XSL to replace XML nodes with new nodes
,
I try to present an xml file into an html table, changing particular nodes in the initial xml.
The question is how I can add the replacements into the html table together with the unchanged nodes and their attributes in one shot in the same xsl. The transformed nodes are shown at the beginning of the page above the table bounds, and disappear from the table body. In addition only nodes seem to change and not their corresponding attributes.
Following are my xml and xsl.
(I have to comment the <!-- <xsl:output method="xml" indent="yes"/> -->
, otherwise the html format is damaged.)
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<Features>
<Feature code="a" price = "1"></Feature>
<Feature code="b" price = "2"></Feature>
<Feature code="c" price = "3"></Feature>
</Features>
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<!-- <xsl:output method="xml" indent="yes"/> -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Feature[@code='c']">
<Feature code="c" name="c11" price="21">C1</Feature>
<br/>
<Feature code="c" name="c12" price="22">C2</Feature>
</xsl:template>
<!-- Main table -->
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd30">
<th>Price:</th>
<xsl:apply-templates select="//Feature"/>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Feature">
<tr bgcolor="#ebf4f3">
<td> <xsl:apply-templates select="@price"/> </td>
</tr>
</xsl:template>
<xsl:template match="@price">
<span style="color:#e5325e">
<xsl:value-of select="."/>
</span>
<br />
</xsl:template>
</xsl:stylesheet>
I appreciate any instructions
2