[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 01:03:12 +0100

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"
   <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:sequence select="sum(key('counts',max($all))/count(@*))"/>

   <xsl:template match="*">
      <xsl:sequence select="count(key('elems',name()))"/>

   <xsl:template match="text()"/>


Current Thread