A
Andy Fish
Hi,
I'm trying to use <xsl:number> to generate a sequence number of all nodes
that match a particular pattern, e.g:
<xsl:template match="foo">
<xsl:copy>
<xsl:attribute name="id"><xsl:number level="any"/></xsl:attribute>
</xsl:copy>
</xsl:template>
this will consecutively number all the <foo> nodes in a document. regardless
of where they appear. However, in my case I have a second pattern:
<xsl:template match="foo[@type='bar']" priority="1">
</xsl:template>
Now, nodes that match the second template are included when generating the
number for the first template, so the numbering within the output document
is no longer consecutive.
I realise that in this trivial case I could have used [@type <> 'bar'] to
explicitly exclude some nodes from the numbering but I'm trying to figure
out if there is a simple way to just say 'count all nodes that are processed
by this pattern' (like if I was using an imperative language I would just
increment a variable every time I output the id attribute)
TIA
Andy
I'm trying to use <xsl:number> to generate a sequence number of all nodes
that match a particular pattern, e.g:
<xsl:template match="foo">
<xsl:copy>
<xsl:attribute name="id"><xsl:number level="any"/></xsl:attribute>
</xsl:copy>
</xsl:template>
this will consecutively number all the <foo> nodes in a document. regardless
of where they appear. However, in my case I have a second pattern:
<xsl:template match="foo[@type='bar']" priority="1">
</xsl:template>
Now, nodes that match the second template are included when generating the
number for the first template, so the numbering within the output document
is no longer consecutive.
I realise that in this trivial case I could have used [@type <> 'bar'] to
explicitly exclude some nodes from the numbering but I'm trying to figure
out if there is a simple way to just say 'count all nodes that are processed
by this pattern' (like if I was using an imperative language I would just
increment a variable every time I output the id attribute)
TIA
Andy