Re: [xsl] Noobie: normalize <b><a>...</a></b> to <a><b>...</b></a>

Subject: Re: [xsl] Noobie: normalize <b><a>...</a></b> to <a><b>...</b></a>
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Fri, 19 Feb 2010 16:57:16 +0000 (GMT)

> 1.  <b> can contain mixed text, in which case nothing should be
> 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>
The following transform, based on the Modified Identity
Transform pattern,
should do that (not tested though):

    <xsl:template match="node()">
          <xsl:copy-of select="@*"/>

match="b[count(a) eq 1][empty(node() except a)]">
<xsl:apply-templates select="a/node()"/>

  This is simple: the first rule catches every node and
copies it,
then continues navigating through its descendents.  But the second
rule applies when the transform go through a special node: a "b"
element with
exactly one child (an "a" element).  In that specific
case it creates two
elements (a "b" within an "a") and continues
navigating through "a"'s


Florent Georges

Current Thread