xsl-list
[Top] [All Lists]

Re: Counting nodes efficiently

2004-02-18 13:45:42
"Brian Grainger" <granam(_at_)operamail(_dot_)com> wrote in message
news:opr3k0tsch8u8pov(_at_)smtpx(_dot_)operamail(_dot_)com(_dot_)(_dot_)(_dot_)
Greetings.

I've been using Jeni's method from the XSLT FAQ to assign unique id's to
nodes. In order to speed things up, can anyone think of a way that I could
store the running totals for the different nodes, rather than having to
call the count() function repeatedly? A generalized method would obviously
be the best, so that it could be applied to any arbitrary set of nodes,
but I don't know if this is even possible.

<xsl:template match="*">
   <xsl:variable name="name" select="name()" />
   <xsl:element name="{name()}">
     <xsl:attribute name="id">
       <xsl:value-of select="concat($name, '-',
       count(preceding::*[name()= $name]) +
       count(ancestor::*[name()= $name]))" />
     </xsl:attribute>
     <xsl:apply-templates />
   </xsl:element>
</xsl:template>

Maybe I don't understand well something -- why don't you use generate-id|()
?


Cheers,

Dimitre Novatchev,
FXSL developer,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>