[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Fw: repeat: XSLT 2.0 Req: Serial transforms (possibly dup of xsl:apply-transform request)


Subject: Re: [xsl] Fw: repeat: XSLT 2.0 Req: Serial transforms (possibly dup of xsl:apply-transform request)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 4 Mar 2001 11:24:35 +0000

Hi Curt,

> In the development of the XML Schema Compiler
> (http://sourceforge.net/projects/xsdcomp), I found it necessary to
> do the transformation from the source XML Schema to the "compiled"
> version as a series of transforms. The first transform resolved the
> included content, the second resolved qname references, and so forth
> in a manner very similar to the passes in a multipass compiler. Each
> pass operated on the output of the preceding pass. So, if you were
> driving it from the command line you would have something like:
>
> saxon -o temp1.xml source.xsd preprocessor.xsl
> saxon -o temp2.xml temp1.xml pass1.xsl
> saxon -o temp3.xml temp2.xml pass2.xsl
> saxon -o temp4.xml temp3.xml pass3.xsl
> ...
> saxon -o output.xml temp4.xml optimize.xsl
>
> It would be beneficial if this type of serial transformation could
> be described in XSLT 2.0 so that the overall transformation process
> could be communicated via a binding between the source document and
> a single XSL file in case you wanted to perform the overall
> transformation on the client side.

'Now' (i.e. with XSLT 1.1) that you can convert result tree fragments
to node sets, then much of the time you can encode multiple passes
within a single stylesheet. Something like:

<xsl:template match="/">
   <xsl:variable name="preprocessed">
      <xsl:apply-templates select="." mode="preprocess" />
   </xsl:variable>
   <xsl:variable name="postpass1">
      <xsl:apply-templates select="$preprocessed" mode="pass1" />
   </xsl:variable>
   <xsl:variable name="postpass2">
      <xsl:apply-templates select="$postpass1" mode="pass2" />
   </xsl:variable>
   <xsl:variable name="postpass3">
      <xsl:apply-templates select="$postpass2" mode="pass3" />
   </xsl:variable>
   ...
   <xsl:apply-templates select="$postpass4" mode="optimize" />
</xsl:template>

This main stylesheet can then be associated with the document with an
xml-stylesheet processing instruction.

You need to add modes to the separate stylesheets and import them all
into the main stylesheet to do this. They can continue to be
standalone as well if you have a simple template to each of them e.g.:

<xsl:template match="/">
   <xsl:apply-templates select="." mode="preprocess" />
</xsl:template>

It's not always a solution (particularly if you're importing
stylesheets with unmoded templates that you want to use into the
various preprocess, pass1, pass2 etc. stylesheets), but it should work
much of the time.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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



Current Thread
Keywords