Re: [xsl] recursivly applying a transform to a result tree

Subject: Re: [xsl] recursivly applying a transform to a result tree
From: "M.A. Voetberg" <marco@xxxxxxxxxxxx>
Date: Mon, 9 Apr 2001 13:24:30 +0200
> This works with processors which support XSLT1.1, for example with
> Saxon 6.2.2.  NB, XSLT 1.1 is not a recommendation yet.  For other
> processors you may be able to use the extension function node-set().
>
> Is this of any help?
>
> Regards,
> Trevor Nash

Thanks,

This does help. At least I can get my example to work with:

<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="a">
  <b><c>
    <xsl:apply-templates />
  </c></b>
</xsl:template>

<xsl:template match="modifyA>
  <xsl:variable name="tree">
    <xsl:apply-templates/>
  </xsl:variable>
  <xsl:apply-templates select="$tree" />
</xsl:template>

<xsl:template match="b/c">
  <d>
    <xsl:apply-templates />
  </d>
</xsl:template>

</xsl:stylesheet>

So that <a/> gives <b><c/><b>,
and <modifyA><a/></modifyA> gives <d />

But this gives the next problem that if the input already has b/c it also
will be transformed to <d />. This
I solved by using mode="tree" in the <xml:apply templates select="$tree" />
and the
<xsl:templates match="b/c">.

It works, but I'm not really charmed about the solution. I also read
something in the XSLT1.1 spec that the result tree fragments were going to
be removed ? But I'm not sure (I'm not getting any response from
w3c.org so I can't look it up). If they remove this feature, I hope they
will add a slightly more elegant way to apply templates to result tree
fragment.

Regards,

Marco Voetberg



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread