[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How can I bend generate-id()?

Subject: How can I bend generate-id()?
From: "Charles Knell" <cknell@xxxxxxxxxx>
Date: Fri, 26 Jul 2002 13:27:30 -0700
textarea onblur
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@xxxxxxxxxx - email
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.