Search code examples
xqueryuuid

How do i generate a random UUID in xquery


Can anyone help me with this one? I want to be able to generate a random UUID in x-query. Is there any function to do this?

thanks!


Solution

  • Using Saxon, you should be able to link to Java to generate the UUIDs like this:

    XSLT

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:uuid="java:java.util.UUID">
    

    XQuery

    declare namespace uuid = "java:java.util.UUID";
    

    Then call the function uuid:randomUUID() anywhere in the stylesheet or XQY script.