xsl-list
[Top] [All Lists]

Re: [xsl] How many passes through the document

2012-09-23 00:32:34
On Sun, Sep 23, 2012 at 1:03 AM, Ihe Onwuka 
<ihe(_dot_)onwuka(_at_)googlemail(_dot_)com> 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.

--~------------------------------------------------------------------
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>
--~--