Re: [xsl] Generating Unique ID

Subject: Re: [xsl] Generating Unique ID
From: Steve Rosenberry <Steve.Rosenberry@xxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 06 Dec 2005 10:31:45 -0500

You can take a look at:

In XMLEditBasicForm.xslt, I create heirarchical id's for div and span elements. Search for "id=" in the file and you'll find text such as:

 div id="{$div_name}"
 span id="{$span_name}"

where $div_name was formed from an id created by the template function found in XMLEditBaseElements.xslt:


create_path() creates addresses (id's) based upon the hierarchical location of an element within the XML file being transformed. (The id's are heirarchical but not necessarily sequential, e.g. there may be gaps in the numbering.) If there is a reasonable correlation between the structure of the XML file and the resulting HTML, this may work for you. If not, it may at least give you some ideas.

FAIR WARNING: My implementation of create_path(), to put it mildly, sucks. Despite my efforts to do a fully recursive version, I could never get it to work. So in the interest of expediency, I did a version which I believe nests to about 5 or 6 levels, but it is brute force and not at all elegant. Feel free to improve upon it as you may.

These files are part of the XMLEdit demo found at:

XMLEdit is a limited function CMS where content is stored in XML files and manipulated through xslt and javascript to change the public website. You can edit the XML in a strictly defined manner and then preview and publish the page. The hierarchical id's are used while editing the XML content. You can see the xslt that uses these id's in action by editing:

Underneath the "Preview Page" button, near the bottom of the page, are two buttons to view either the underlying XML data for the page or the transformed HTML that created the page.

Hope this helps.

Steve Rosenberry
Sr. Partner

Electronic Solutions Company -- For the Home of Integration

(610) 670-1710

Arun Sinha wrote:

Hi Ragulf,

Actualy the HTML page that I am producing has a drilldown facility.
When the page is called for the first time only the level one data is shown with closing folder
picture. When the folder is clicked then the next level data is shown.

To get this working the javascript, that we have, needs IDs like that.

Best Regards.


From: "Ragulf Pickaxe" <ragulf.pickaxe@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Generating Unique ID
Date: Tue, 06 Dec 2005 09:35:23 +0100

Hi Arun,

Why do you need the id to contain its parents id as well?

You have a function, generate-id(), which generates a unique id on a node.

If you need an id like what you state, you will need to do something like this (a variation of identity template):

<xsl:template match="*">
<xsl:variable name="special-id">
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="generate-id(.)"/>
<xsl:copy-of select="@*"/>
<xsl:attribute name="ID"><xsl:value-of select="$special-id"/></xsl:attribute>

Is the above what you need?

Ragulf Pickaxe :-)

Find det, du sxger pe MSN Sxg

Current Thread