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

Re: [xsl] Alphabetical index: unstreamable?

Subject: Re: [xsl] Alphabetical index: unstreamable?
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 Jun 2014 14:05:29 -0000

On 28-5-2014 14:35, Michael M|ller-Hillebrand mmh@xxxxxxxxx wrote:
> Dear all,
> In documents the content of what will end up in an alphabetical index is usually authored in the section to which the index term belongs. That is, index terms are usually all over the place.
> When it is time to create an alphabetical index, I see that the XSLT handling this uses something like
> <xsl:call-template name="index">
>   <xsl:with-param name="terms"  select="//indexterm" />
> </xsl:call-template>
> and inside the called template all the sorting and grouping is handled.
> This is not streamable because there is more than a single downward select (and it is easy to see that you need everything in memory to create the sequence of all <indexterm>).

Actually, there is one explicit downward select, //indexterm, which on
itself can return overlapping nodes, which makes it (on itself) not
streamable. But in some contexts, notably "inspection contexts", it is
allowed: count(//indexterm) or if(//indexterm) then...

That said, using xsl:call-template in a streamable context is severely
- you cannot pass the context item implicitly
- you cannot pass references to nodes in xsl:with-param

To use xsl:call-template you need to prohited the context-item using
<xsl:context-item use="prohibited" />. And if you want to pass
information in a node, you should copy the node, i.e. with
fn:copy-of(x). In your case however, neither will help you, because
fn:copy-of does not work with overlapping nodes (but this may change,
see public XSLT Spec Bug 25185, comment 7:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=25185#c7). Besides, I
assume you want to process the input document both for collecting the
indexes _and_ for processing of other nodes.

Further on in this thread you already came up with using accumulators,
I'll reply to that mail for some further info on creating indexes with
streamable documents.


Abel Braaksma
Exselt XSLT 3.0 streaming processor

Current Thread