Sample code showing how to generate unique IDs using XSL and Java. I am running Saxon 9 and Java 1.6.
First, set up the xmlns:uuid extension at the stylesheet level.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:uuid="java:java.util.UUID">
Later on, create a random unique ID using the uuid extension.
<xsl:variable name="uid" select="uuid:randomUUID()"/>
Output the value of the unique ID.
<xsl:value-of select="$uid"/>
I like to set up an attribute set to reuse.
<xsl:attribute-set name="uid">
<xsl:attribute name="id">
<xsl:variable name="uid" select="util:randomUUID()"/>
<xsl:value-of select="$uid"/>
</xsl:attribute>
</xsl:attribute-set>
And then reference it when creating the result.
<some-element xsl:use-attribute-sets="uid"/>