Jeff,
Below appears an example stripped down from a working stylesheet. It does
something a bit different from what you need, but it illustrates two passes
using a node-set extension.
The function in this case is bound to the exslt namespace. Check out
exslt.org for more on this, as well as your processor's documentation on
available extension functions.
The first pass here processes a bunch of <meta> elements assembled from
various files, whose names are assigned to the $files variable. (In the
actual stylesheet this assembly is more complex; this is simplified here.)
The second pass will be processing this aggregated metadata for display;
but it can't simply process the nodes in their original form, in part since
the aggregation will be sorted, but the sort criteria are not all explicit
in the data. (This is the reverse of your case, in which the sorting would
happen in the first pass.) In order to generate these sort criteria, the
<meta> elements are processed in a special mode, "init" (mostly not shown
here). The result is then made into a node-set and bound to a variable,
which can then be processed further.
The running version of this code may be seen at
sonneteer.xmlshoestring.com, a demonstration project of mine. (All this
runs on XML source server-side in 4Suite, an XML application framework. One
sort criterion of interest here is a poem's rhyme scheme: although the
rhyme scheme of each poem is not actually explicit, as such, in its
tagging, it can easily be derived from it, which is one of the things that
happens in the "init" phase. In fact, strictly speaking this particular
sort can be achieved in one pass; but there are a couple of other things
happening, including parameterizing to handle other sort orders, that make
it very convenient to do in two.)
Here's the code, stripped down to illustrate the principle:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
extension-element-prefixes="exslt">
<xsl:variable name="files" select="//file"/>
<xsl:variable name="metaRTF">
<xsl:apply-templates select="document($files)/*/meta" mode="init"/>
</xsl:variable>
<xsl:template match="meta" mode="init">
<!-- ... selects stuff out of the meta elements at the top level,
and adds some special stuff ... -->
</xsl:template>
<!-- trimming the metadata model not to include
this stuff -->
<xsl:template match="source | remark" mode="init"/>
<!-- most of the init mode is an identity transform -->
<xsl:template match="node()|@*" mode="init">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="init"/>
</xsl:copy>
</xsl:template>
<!-- the variable declaration to create a node-set we can process
out of the result of the 'init' pass -->
<xsl:variable name="meta-collection"
select="exslt:node-set($metaRTF)"/>
<!-- leaving this around just in case we need it -->
<xsl:template match="/" mode="debug">
<xsl:copy-of select="$meta-collection"/>
</xsl:template>
<xsl:template match="/">
<html>
<!-- html stuff goes here-->
<body>
<!-- more html stuff goes here -->
<div class="portfolio">
<xsl:apply-templates select="$meta-collection/meta">
</div>
</body>
</html>
</xsl:template>
<!-- we process our "initialized" node set in the unnamed mode -->
<xsl:template match="meta">
<!-- etc.... -->
</xsl:template>
<!-- etc.... -->
</xsl:stylesheet>
This is the kind of thing David was talking about.
I hope this helps,
Wendell
At 07:01 PM 11/25/2003, you wrote:
Would it be too
much trouble to ask either of you for an example of a two-pass process?
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list