[xsl] recursivly applying a transform to a result tree

Subject: [xsl] recursivly applying a transform to a result tree
From: "M.A. Voetberg" <marco@xxxxxxxxxxxx>
Date: Sun, 8 Apr 2001 13:24:22 +0200

I'm fairly new at XSL/XSLT and so far it is impressive. But I am wondering
about one thing.

In short:

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 ?

The long version:

Recursivly applying a transform to a result tree fragment is basically
equivalant to recursing the transform with the result tree fragment as the
source and a new stylesheet for processing:


<xsl:template match="A">
      <xsl:appy-templates />

applied to <A/> gives <B><C/></B>.

Suppose we introduce a new feature to XSLT something like this:

<xsl:template match="ModifyA">

      <xsl:apply-templates />

      <xsl:template match="B/C">
          <xsl:apply-templates />


The xsl:transform-source is denotes the source for the recursive transform.
In this case the result tree fragment created from xsl:apply-templates is
The xsl:stylesheet is used as normal.

applied to:


first the result tree fragment is created as normal from the children of


this is used as the source for the recursive transform which eventually
gives us:


and this is copyied to the output.

Of course this behaviour can be "faked" by using two stylesheets. The first
we apply to the source
document and the second to the result of the first. But then we would need
to have a rule
in the first to make sure that the ModifyA element does not disappear.

I think something that looks like what I described above would make a
valuable addition to the language.
At least for some special types problems. It would (I think ?) be useful for
increased reusabiliy of a template.

I have been going over this process in my mind an I can find any reasing why
this recursive scenario would
not work. And I can't find another way for this effect to be achieved. But
perhaps I missing something here ?
It seems odd to have a language where everything is recursive except the
toplevel process and implementation wise it should be a breeze to
incorporate this.

I hope someone can help me with these questions ?

Marco Voetberg

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

Current Thread