Re: [xsl] Generating attributes from the position of an element

Subject: Re: [xsl] Generating attributes from the position of an element
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 02 Jun 2010 11:08:04 +0100
On 02/06/2010 09:22, Gabor Tsth wrote:
Dear All,

Thanks for your answers, Michael I tried it out and it worked,
however, I have not so far managed to install Saxon to my Mac, so as a
temporal solution I am using a Firefox adds-on, called "Get XSLT
results" and it has two options for creating transformations, one is
the Saxon 9B, and the other one is called "Built-in XSLT", if I am
trying with the Saxon 9B option, it does not generate the id for this

Given this source document:

<w ID=" " >car</w>
<w ID=" ">dog</w>
<w ID=" ">cat</w>
<w ID=" ">house</w>

and this stylesheet

<xsl:stylesheet xmlns:xsl="";

<xsl:template match="@*|node()|comment()|processing-instruction()">
<xsl:copy><xsl:apply-templates select="@*|node()|comment()|processing-instruction()"/></xsl:copy>

<xsl:template match="@ID">
<xsl:attribute name="Id">
<countNo><xsl:number count="w"/></countNo>


Saxon produces this output:

<?xml version="1.0" encoding="UTF-8"?><text>
<w Id="1">car</w>
<w Id="2">dog</w>
<w Id="3">cat</w>
<w Id="4">house</w>

Note, I had to remove the xpath-default-namespace attribute, because your input is not in a namespace. Perhaps the stylesheet worked with the Transformiix processor because an XSLT 1.0 processor running a stylesheet that specifies version="2.0" will ignore the xpath-default-namespace attribute.

If you're having problems installing Saxon on your Mac, you might find that "Kernow for Saxon" is easier to install. and use This will automatically install Saxon as well as Kernow.

Michael Kay

Current Thread