Re: [xsl] grouping + global variable (?) (was re: regexs, grouping (?) and XSLT2?)

Subject: Re: [xsl] grouping + global variable (?) (was re: regexs, grouping (?) and XSLT2?)
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 12 Aug 2004 17:29:44 -0400
Bruce,

At 04:56 PM 8/12/2004, you wrote:
OK. I understand this conceptually, but I never understood how to create -- and to access -- this "intermediate version".

There are several approaches to doing this kind of pipelining:


1. Poor man's version: run two stylesheets in succession: the second runs on the result of the first. Good for prototyping and debugging and even works in a production environment. Downside: very old-fashioned; slow; requires cleanup.

2. Extended XSLT 1.0: create your first result by applying templates to your source and binding the results to a variable, which you then use a processor extension to turn into a node set for further processing. You'll probably need modes (if only to keep yourself sane), so:

<xsl:variable name="intermediate-result">
  <xsl:apply-templates select="/" mode="pass1"/>
</xsl:variable>

<xsl:template match="/">
<xsl:apply-templates select="exslt:node-set($intermediate-result)" mode="pass2"/>
</xsl:template>


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

where exslt:node-set is an extension function that creates a node-set from a result-tree-fragment (see exslt.org or consult your processor's documentation).

3. XSLT 2.0 -- same as 2, except no extension function is needed: it'll happen transparently.

4. External pipeline support: many environments, and some processors, allow you to chain stylesheets directly, thereby eliminating the need to write out the intermediate result as a file (as option 1 does). This is the in-between solution. For example, Saxon has a saxon:next-in-chain attribute you can use on xsl:output.

Jeni was less than specific because there are so many ways to do this, which you should use depends on your own case, and she has a baby to feed. (Waa!)

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread