[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 12:29:57 +0100

On Sun, Sep 23, 2012 at 8:59 AM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> Firstly, it depends on the processor, and secondly it doesn't really matter.
>
> One processor might build indexes for both keys in a single pass of the
> document, another might make one pass of the document for building each key.
> Either strategy might be faster. Why do you care which strategy is used -
> surely it's only the bottom-line performance that matters to you?
>
> There does seem to be an intrinsic inefficiency in that you are evaluating
>
> count(key('elems',name()))
>
> twice for each element: once when building the "counts" index, and once
> during the apply-templates. But it's not a very big inefficiency.
>

Given that solution is that avoidable?

> Rather more importantly, your code is incorrect: because of the way it uses
> name(), it won't produce sensible answers when applied to a document that
> binds the same prefix to different namespaces (or has two different default
> namespaces in different regions of the document). In 2.0, use node-name()
> instead.
>

is that saying that name() is deprecated?

> I think you are just trying to output the number of occurrences of the
> element whose name occurs most frequently. If that's the case, try
>
> <xsl:template match="/">
>   <xsl:for-each-group select="//*" group-by="node-name()">
>     <xsl:sort select="count(current-group())" order="descending"/>
>     <xsl:if test="position()=1"><xsl:value-of
> select="count(current-group())"/></xsl:if>
>   </xsl:for-each-group>
> </xsl:template>
>

printing the total number of attributes in the elements whose name
occurs most frequently. Interesting to see a different approach, that
was what I was hoping for.


Current Thread