xsl-list
[Top] [All Lists]

Re: [xsl] counting the element number in a recursive tree

2006-06-26 04:35:19
Thanks

If position() returns even numbers, it's because you are counting text nodes
as well as elements. The answer is to count only the elements, which will
happen if you use <xsl:for-each select="*"> or <xsl:apply-templates
select="*"> rather than using select="node()".

I didn't used select="node()", but just called <xsl:apply-templates
/>, so it would be applied to all descendant recursively I think.
Using <xsl:apply-templates select="*" />, the problem was there, but
<xsl:number level="single" /> was what I wanted.


Dividing position() by 2 is wrong, because the whitespace text nodes won't
always be there.

Alternatively, use xsl:number.

Michael Kay
http://www.saxonica.com/


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