This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
How can I bend generate-id()?
- From: "Charles Knell" <cknell at onebox dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Cc: martincd at eis dot army dot mil
- Date: Fri, 26 Jul 2002 13:27:30 -0700
- Subject: [xsl] How can I bend generate-id()?
- Reply-to: xsl-list at lists dot mulberrytech dot com
I have a transformation which produces multiple output nodes for each
input node. I need to place an id attribute into each output node. At
first I thought, "I'll just use the generate-id() function!", but after
doing that I found that I had identical values for the id attributes
of those output nodes generated from the same input node.
Referring to XSLT Programmer's Reference 2nd Edition, page 492, I read
"If the argument is omitted, the target node is the context node." by
which I understand that the since the context node is not changing between
emissions of the generated-id function, each return value of generate-id()
will be identical until I change context nodes.
Is there some way in which I could "bend" generate-id() so as to produce
two or more unique id's from the same context node? Will I have to use
some baroque recursive template call, passing a number as a parameter
which will be incremented with each recursion and then appended to the
value returned by generate-id() so as to achive more than one unique
id from multiple calls to generate-id() from the same context node? (Please
tell me there is an easier way!)
Here is the template and the output:
template
===================================================
<xsl:template match="node">
<xsl:param name="depth" select="0" />
<xsl:param name="tabSize" select="1" />
<div id="{generate-id()}" drag="enable" style="position:relative;left:{$tabSize
* $depth}px;">
<xsl:variable name="level">
<xsl:value-of select="$depth + 1" />
</xsl:variable>
<xsl:if test="$depth != 0">
<img src="{$bulletURL}" id="{generate-id()}" />
</xsl:if>
<textarea id="{generate-id()}" class="editableNode" onfocus="Sink()"
onblur="Sink()">
<xsl:value-of select="normalize-space(text()[position()=1])" />
</textarea>
<xsl:apply-templates select="./*">
<xsl:with-param name="depth" select="$level" />
<xsl:with-param name="tabSize" select="$tabSize" />
</xsl:apply-templates>
</div>
</xsl:template>
output
===================================================
<div style="position:relative;left:0px;" drag="enable" id="N400003">
<textarea onblur="Sink()" onfocus="Sink()" class="editableNode" id="N400003">Topic
A</textarea>
<div style="position:relative;left:10px;" drag="enable" id="N400005">
<img id="N400005" src="bullet.gif"><textarea onblur="Sink()" onfocus="Sink()"
class="editableNode" id="N400005">Subtopic A.1</textarea>
<div style="position:relative;left:20px;" drag="enable" id="N400007">
<img id="N400007" src="bullet.gif"><textarea onblur="Sink()" onfocus="Sink()"
class="editableNode" id="N400007">Subtopic A.1.a</textarea>
</div>
</div>
</div>
<div style="position:relative;left:0px;" drag="enable" id="N400009">
<textarea onblur="Sink()" onfocus="Sink()" class="editableNode" id="N400009">Topic
B</textarea>
</div>
--
Charles Knell
cknell@onebox.com - email
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list