[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: General trick for re-applying recursivly/iterative

Subject: RE: General trick for re-applying recursivly/iteratively a XSLT Script until no changes? Preferable with XSLT v1.1
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 4 Dec 2009 13:20:09 -0000
RE:  General trick for re-applying recursivly/iterative
If you are transforming using a "modified identity transform", then you
could make the identity template rule set an attribute changed="no", and
every other template rule that creates an element set changed="yes", and you
could then detect whether anything has changed using //@changed[.='yes'].

How you implement the "keep transforming until no change" depends rather on
the environment you are running in. You could do it of course using
recursion within the stylesheet itself:

<xsl:template match="/">
  <xsl:variable name="out">
    <xsl:when test="$out//@changed='yes'">
      <xsl:apply-templates select="$out"/>
      <xsl:copy-of select="$out"/>

In 2.0 an alternative would be do test deep-equal(/, $out).

In practice such repeated transformations arise in optimization scenarios -
see my paper at Extreme Markup 2007. It might be a good idea if this is your
application domain to look at the literature on "simulated annealing".


Michael Kay

> -----Original Message-----
> From: Wolfgang Laun [mailto:wolfgang.laun@xxxxxxxxx]
> Sent: 04 December 2009 12:41
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  General trick for re-applying
> recursivly/iteratively a XSLT Script until no changes?
> Preferable with XSLT v1.1
> Simply comparing the size of the input and the output file
> (and calling the straightforward XSLT script over again)
> might do the trick for pruning; if you need to guard against
> replacment operations that might not change the size, cmp or
> diff would provide an indication of "no change".
> -W
> On Fri, Dec 4, 2009 at 10:48 AM, Andrew Welch
> <andrew.j.welch@xxxxxxxxx> wrote:
> >
> > 2009/12/4 Ben Stover <bxstover@xxxxxxxxxxx>:
> > > In general when I apply a XSLT script then one
> rule/template is matched at a time (for one node).
> > > Then the XSLT script is stopped.
> > >
> > > Imagine for example a template which deletes (only) the current
> > > leaves of an XML node tree. When the current leaves are
> removed then there are new leaves.
> > >
> > > Is there a general (!) trick to re-apply the script on
> the resulting XML doc again?
> > >
> > > Again: I am not searching for a specific solution but a general
> > > trick which works for (almost) all XSLT scripts. The processing
> > > should only stop with the re-application when there is no
> difference any more between input and output XML.
> > >
> > > This general trick should preferably work with XSLT v1.1
> (if not possible then v2.0 is ok as well).
> >
> >
> > A couple of points here:
> >
> > - XSLT 1.1 was dropped in favour of going straight to 2.0,
> so it's not
> > clear why you would want 1.1?
> >
> > - You've written a wordy description with no input/output
> examples, so
> > it's hard to understand and even harder to give a precise reply
> >
> >
> >
> > --
> > Andrew Welch
> > http://andrewjwelch.com
> > Kernow: http://kernowforsaxon.sf.net/

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.