[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: FW: I need help with converting XML document diff
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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|