xsl-list
[Top] [All Lists]

Re: [xsl] How many passes through the document

2012-09-23 06:30:19
On Sun, Sep 23, 2012 at 8:59 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> 
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--