[Home] [By Thread] [By Date] [Recent Entries]
Johnson, Mike wrote:
Example XML Document: <?xml version="1.0" encoding="utf-8"?> The following is an identity transformation plus a template for tr elements ensuring that transforms them into item elements wher only the attributes and the td elements are processed plus a template that transforms td elements into attributes:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template> <xsl:template match="tr">
<item>
<xsl:apply-templates select="@* | td"/>
</item>
</xsl:template> <xsl:template match="td">
<xsl:attribute name="{@colnum}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template></xsl:stylesheet> That should do what you described, with the exception of those spaces in front of e.g. c1=" E1c06". If you really want those then you need
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template> <xsl:template match="tr">
<item>
<xsl:apply-templates select="@* | td"/>
</item>
</xsl:template> <xsl:template match="td">
<xsl:attribute name="{@colnum}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template> <xsl:template match="td[@colnum = 'c1']">
<xsl:attribute name="{@colnum}">
<xsl:value-of select="concat(' ', .)"/>
</xsl:attribute>
</xsl:template></xsl:stylesheet> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/
|

Cart



