RE: [xsl] Problem getting position of node

Subject: RE: [xsl] Problem getting position of node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 21 Mar 2006 09:22:03 -0000
> <xsl:template match="@*">
> <xsl:attribute name="{name(.)}">
> <xsl:value-of select="."/>
> <xsl:number count="*"/>
> </xsl:attribute>
> </xsl:template>
> 
> 
> As you can see, the context node is an attribute node and Iam 
> getting the
> error,
>  Attribute nodes cannot be numbered.

Whichever processor is telling you that attributes cannot be numbered is
wrong. It doesn't make much sense to number them, but it's perfectly
permissible to do it, and the result is well defined.

However, if you're positioned on an attribute and you want the number of the
parent element, in XSLT 2.0 you can do

<xsl:number select=".." count="*"/>

or in XSLT 1.0

<xsl:for-each select="..">
  <xsl:number count="*"/>
</xsl:for-each>


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

Current Thread