Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate GUID in XSLT

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.

like image 932
Burt Avatar asked Mar 31 '11 00:03

Burt


2 Answers

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.

like image 62
Wayne Avatar answered Oct 16 '22 16:10

Wayne


C# provides a handy Guid.NewGuid() static method. I'd expect any XSLT implementation would heavily leverage some system-specific component since Guids are often generated in part based on hardware/MAC address/etc. on the underlying machine.

like image 21
Joe Avatar answered Oct 16 '22 15:10

Joe