This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: recursivly applying a transform to a result tree
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] recursivly applying a transform to a result tree
- From: tcn at melvaig dot co dot uk (Trevor Nash)
- Date: Sun, 08 Apr 2001 15:49:56 GMT
- Organization: Melvaig Software Engineering Limited
- References: <003e01c0c01e$75e90050$1e01000a@defiant>
- Reply-To: xsl-list at lists dot mulberrytech dot com
>The language is completly recursive by nature and obviously so is an
>implementation of the transform.
>But something strikes me as being very odd. Why are there no facilities for
>recursivly applying a transform to a result tree fragment ? Is this a design
>philosophy or perhaps a omission cq flaw ?
Is this the sort of thing you have in mind:
given <a depth="n"/> the following transform yields an <a> element
with n nested <x> elements, e.g.
<a depth=3/>
gives
<a><x><x><x/></x></x></a>
(its not supposed to be useful, just to demonstrate).
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().
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
>
<xsl:template match="a[@depth=0]">
<a><xsl:copy-of select="child::node()"/></a>
</xsl:template>
<xsl:template match="a[@depth>0]">
<xsl:variable name="tree">
<a depth="{@depth - 1}">
<x><xsl:copy-of select="node()"/></x>
</a>
</xsl:variable>
<xsl:apply-templates select="$tree"/>
</xsl:template>
</xsl:stylesheet>
Is this of any help?
Regards,
Trevor Nash
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list