I need to generate unique IDs for elements across multiple XML files using XSLT. Each of the elements in question is already provided an ID that is gaurenteed to be unique within its own file, but can (and will) overlap with the IDs of nodes in other files.
My solution has been to concat the file path to the beginning of the existing ID, but this poses 2 problems:
- Publishing the filepath is a less than ideal solution, and may pose a legal/security risk.
- It makes for some very long, and verbose IDs filled with illegal characters (slashes, anyone?). The output is an HTML page, and many of the computers accessing it are old, and run ancient picky browsers.
This is the code I'm running with, currently:
<xsl:template match="box">
<div class="box">
<xsl:attribute name="id">
<xsl:value-of select="$file_path" /><xsl:value-of select="./@id" />
</xsl:attribute>
... blah blah content blah ...
</div>
</xsl:template>
$file_path
is passed in as a param automatically by the system.
So, yes, while this (technically) works, it is far from up to snuff. What I'd like to do is hash the variable $file_path
before jamming together with the other ID. It doesn't have to be super secure, just obfuscated enough so that it doesn't resemble a path, is totally alpha-numeric, and is, preferably, shorter (bonus points if all hashes are the same length).
Finally (and this is the clincher) it almost certainly has to work in XSLT 1.0. It may be possible to persuade the powers that be to upgrade, but for all intents and purposes I need to know if this can be done without XSLT 2.