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

Re: [xsl] How many passes through the document

Subject: Re: [xsl] How many passes through the document
From: Ihe Onwuka <ihe.onwuka@xxxxxxxxxxxxxx>
Date: Sun, 23 Sep 2012 06:32:22 +0100

On Sun, Sep 23, 2012 at 1:03 AM, Ihe Onwuka <ihe.onwuka@xxxxxxxxxxxxxx> wrote:
> Of course if I had written it like this with the variable local
> instead of global I wouldn't be asking the question.
> So I guess the question is whether the global version entails an extra
> pass over the data or any other performance penalty.
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 version="2.0"
>                 exclude-result-prefixes="xs">
>    <xsl:output method="text"/>
>    <xsl:key name="elems" match="*" use="name()"/>
>    <xsl:key name="counts" match="*" use="count(key('elems',name()))"/>
>    <xsl:template match="/">
>       <xsl:variable name="all" as="xs:integer+">
>          <xsl:apply-templates select="*"/>
>       </xsl:variable>
>       <xsl:sequence select="sum(key('counts',max($all))/count(@*))"/>
>    </xsl:template>
>    <xsl:template match="*">
>       <xsl:sequence select="count(key('elems',name()))"/>
>       <xsl:apply-templates/>
>    </xsl:template>
>    <xsl:template match="text()"/>
> </xsl:stylesheet>

Engaging brain fully now and  believe I can answer my own question.

The only time templates are applied to * is when the variable is
evaluated so whether it is global or local shouldn't make a difference
performance wise.

Current Thread