Subject: Re: [xsl] Noobie: normalize <b><a>...</a></b> to <a><b>...</b></a> From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Thu, 18 Feb 2010 19:09:04 +0100 |
I'm converting a non-XML data-dump into XML, and the document contains examples of both
<a><b>...</b></a>
and
<b><a>...</a></b>
which (in this document) are equivalent. I'd like to use XSLT to convert all examples of the latter to the former, with the following caveats:
1. <b> can contain mixed text, in which case nothing should be changed.
2. <b><a>...</a></b> should be changed to <a><b>...</b></a> only if the <a>...</a> element is the unique child node of <b>...</b>
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
<xsl:template match="b[a and not(a[2]) and not(node()[not(self::a)])]"> <a> <b> <xsl:apply-templates select="a/node()"/> </b> </a> </xsl:template>
Martin Honnen http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Noobie: normalize <b><a>...</, Kenneth Reid Beesley | Thread | RE: [xsl] Noobie: normalize <b><a>., Michael Kay |
[xsl] Noobie: normalize <b><a>...</, Kenneth Reid Beesley | Date | RE: [xsl] Noobie: normalize <b><a>., Michael Kay |
Month |