Generate GUID in XSLT

Burt picture Burt · Mar 31, 2011 · Viewed 11k times · Source

I need to generate a GUID with XSLT and if needed C#, does anyone know how to best do this?

It is to generate unique IDs for HTML items.

Answer

Wayne picture Wayne · Mar 31, 2011

The XSLT generate-id function returns a string that uniquely identifies a node in the document. Note these warnings from the spec:

An implementation is under no obligation to generate the same identifiers each time a document is transformed. There is no guarantee that a generated unique identifier will be distinct from any unique IDs specified in the source document.

However, if all you need is to uniquely identify each element in your output, then generate-id is sufficient.