Re: [xsl] Numbering new nodes using consecutive integers

Subject: Re: [xsl] Numbering new nodes using consecutive integers
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Fri, 27 Mar 2009 19:05:12 +0100
G. Ken Holman schrieb:
<xsl:number> should be used for adding text to the result tree and
only used in variables as a last resort.

I think I may have heard that last week ... :-)


Now it would be perfect if the numbering was done as a strict
sequence of consecutive integers, meaning 1,2,3 instead of, say,
1,3,5.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="2.0">

        <xsl:attribute name="no"
               select="position() (:within this group:) +
                       (:count of subgroups within previous groups:)
                       sum( for $g1 in ../preceding-sibling::G1 return
                            ((count($g1/M)-1) idiv $M-per-G2 + 1) )"/>

Perfect! Thanks!


(I made a note to remember using XPath 2.0 comments to make complex
expressions less cryptic.)

Michael Ludwig

Current Thread