Re: [xsl] question about generate-id()

Subject: Re: [xsl] question about generate-id()
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 07 Aug 2010 17:56:59 +0100
I don't follow your argument, Dave. An input document's identifiers
have *no* relationship to generate-id().
Lets agree to differ on that one then Ken.

Well, Ken is saying what the spec says, and Dave is saying what he would like it to say instead, and it's not logically inconsistent that these two things should be different.

There are certainly use cases where a function generate-new-id() specified as Dave would like might be useful. You could code it like this:

<xsl:function name="generate-new-id" as="xs:string">
<xsl:param name="node" as="node()"/>
<xsl:sequence select="generate-new-id(0)"/>

<xsl:function name="generate-new-id" as="xs:string">
<xsl:param name="node" as="node()"/>
<xsl:param name="seq" as="xs:integer"/>
<xsl:variable name="gid" select="concat(generate-id($node), '-', $seq)"/>
<xsl:sequence select="if (exists($node/id($gid))) then generate-new-id($node, $seq+1) else $gid"/>

If you want that function, you are welcome to use it. If you prefer the generate-id() that's in the standard function library, then use that.

Michael Kay
<xsl:sequence select="generate-unique-id(0)"/>

Current Thread