Name

cx:unique-id — Generates unique identifiers.

Synopsis

Input portPrimarySequenceContent types
source✔  xml html 
Output portPrimarySequenceContent types
result✔  text xml html 
Option nameTypeValuesDefault value
flavorxs:string('uuid','ulid','typeid') 'uuid'
matchxs:string /*
parametersmap(xs:QName,item()*)? ()
sequentialxs:boolean false()
Declaration
 1 |<p:declare-step xmlns:p="http://www.w3.org/ns/xproc">
   |   <p:input port="source" primary="true" content-types="xml html"/>
   |   <p:output port="result" content-types="text xml html"/>
   |   <p:option name="match" as="xs:string" select="/*"/>
 5 |   <!-- XSLTSelectionPattern -->
   |   <p:option name="flavor"
   |             as="xs:string"
   |             select="'uuid'"
   |             values="('uuid','ulid','typeid')"/>
10 |   <p:option name="sequential" as="xs:boolean" select="false()"/>
   |   <p:option name="parameters" as="map(xs:QName,item()*)?"/>
   |</p:declare-step>

Description

The cx:unique-id step generates a unique identifier and injects it into the source document. UUID, ULID, and TypeID identifiers are supported.

Options

There are four options. The parameters vary by flavor.

match

The value of the match option must be an XSLTSelectionPattern.

The matched nodes are specified with the selection pattern in the match option. For each matching node, the generated identifier is used in the output. Nodes that do not match are copied without change.

If the expression given in the match option matches an attribute, the identifier is used as the new value of the attribute in the output. If the attribute is named xml:base, the base URI of the element must also be amended accordingly.

If the document node is matched, the entire document is replaced by a text node with the identifier. What appears on port result is a text document with the text node wrapped in a document node.

If the expression matches any other kind of node, the entire node (and not just its contents) is replaced by the identifier.

flavor

The flavor option determines the flavor of identifier.

uuid

If the UUID flavor is selected, the parameters map may contain a version parameter determines the version of the UUID that must be computed. It is a dynamic error (err:XC0060) if the processor does not support the specified version of the UUID algorithm. If the version is not specified, version 4 UUIDs are computed.

Seven UUID versions are supported.

Version 1

Version 1 UUIDs are time based, no other parameters are used.

Version 2

Version 2 UUIDs have two parameters: domain and value. The (integer) value is encoded using the domain. The domain value is either a byte or one of the special values user, group or org (or organization).

The sequential option has no effect.

Version 3

Version 3 UUIDs have two parameters, a namespace UUID and a value. The value is encoded using the namespace and hashed with MD5. The namespace value is either a UUID or one of the special values url (or uri), dns, oid (or iso-oid), or x500.

The sequential option has no effect.

Version 4

Version 4 UUIDs are random, no other parameters are used.

Version 5

Version 5 UUIDs are just like version 3 UUIDs, except that they’re hashed using SHA1 instead of MD5.

Version 6

Version 6 UUIDs are time based, no other parameters are used.

Version 7

Version 7 UUIDs are time based, no other parameters are used.

ulid

ULIDs have no parameters.

typeid

TypeID identifiers have a type parameter which must be a string.

sequential

If sequential is true, a different unique identifier will be generated for each match. Otherwise, the same identifier is used in each match.

Document properties

If the resulting document contains exactly one text node, the content-type property is changed to text/plain and the serialization property is removed, while all other document properties are preserved. For other document types, all document properties are preserved.

References