Subject: Re: [xsl] generate-id accross different xsl files From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Sat, 5 May 2001 12:37:37 +0100 |
Hi Heath, > Will generate-id always produce the same id for a node in an xml > document with different stylesheets? No (or rather, it might do, but it's not guaranteed to). > If not does anyone know a different way to link views in html of an > xml document when the tags in the xml document are not marked with > any id's? You need to construct an ID that reflects something unique and unchanging about the nodes that provide the information in your source XML. This has to be a valid ID, so it has to start with a letter and not contain any spaces, but you can easily just add a letter to the start and substitute all spaces with hyphens or underscores using translate(). The easiest thing to use is the value of the node itself, one of its children or an attribute, or a combination of several of these concatenated together. The less information you use and the closer it is to the node, the better, as this reduces the processing that's needed to generate the IDs. If there's no way of generating something unique from the information available around the node, then you can use the fact that it has a unique position within the XML document to give you the ID. Two ones that I might use are the following: - element name + count of previous elements with the same name <xsl:variable name="name" select="name()" /> <xsl:value-of select="concat($name, '-', count(preceding::*[name() = $name])" /> - 'node-' + hierarchical number <xsl:text />node-<xsl:number count="*" level="multiple" /> These are both pretty inefficient. Depending on the way you're constructing your output you might be able to come up with a way of passing down partial IDs through parameters or something to make it more efficient. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] generate-id accross different, Heath Wilkinson | Thread | Re: [xsl] generate-id accross diffe, Francis Norton |
[xsl] generate-id accross different, Heath Wilkinson | Date | RE: [xsl] generate-id accross diffe, Chris Bayes |
Month |