xsl-list
[Top] [All Lists]

Re: [xsl] How many passes through the document

2012-09-22 19:03:25
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>

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