I experienced a strange behaviour of the saxon XSLT processor which I don't know whether it's a bug or a feature: generate-id() does not generate the same ID on identical nodes. (To make things clear, I use a very short transformation stylesheet. One can achieve the same output in a simpler way, but then we don't see the effect.)
The input XML is as simple as follows:
<list>
<entry>beta</entry>
<entry>gamma</entry>
<entry>alpha</entry>
</list>
This input is transformed by
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<output>
<xsl:apply-templates/>
<xsl:call-template name="mkIndex">
<xsl:with-param name="rootParam" select="." />
</xsl:call-template>
</output>
</xsl:template>
<xsl:template match="entry">
<a id="{generate-id(.)}">
<xsl:apply-templates/>
</a>
</xsl:template>
<xsl:template name="mkIndex">
<xsl:param name="rootParam"/>
<xsl:variable name="rootVar">
<xsl:copy-of select="."/>
</xsl:variable>
<!-- use $rootParam here to get the correct IDs with generate-id()-->
<xsl:for-each select="$rootVar//entry">
<xsl:sort select="."/>
<a href="#{generate-id(.)}">
<xsl:copy-of select="text()"/>
</a>
</xsl:for-each>
</xsl:template>
</xsl:transform>
Using this stylesheet all IDs generated in mkIndex
start with d2
while the "basic" IDs start with d1
.
If you use the variable $rootParam
instead of $rootVar
the IDs generated in mkIndex
look the same as the "basic" IDs. Texts are the same in both cases, therefore we handle the same nodes in both cases.
I don't understand why identical nodes get different IDs with generate-id(). Maybe someone can explain the difference.
Thank you,
leu