Re: [xsl] How can I bend generate-id()?

Subject: Re: [xsl] How can I bend generate-id()?
From: "Charles Knell" <cknell@xxxxxxxxxx>
Date: Fri, 26 Jul 2002 14:04:01 -0700
First let me apologize to those whose email rendered the included HTML
output. I wasn't thinking and I hope it has not inconvenienced anyone
terribly.

Second, in the words of Gilda Radner as Emily Letella, "Never mind."
I was able to solve the problem with twelve keystrokes and the realization
that my template would only output a maximum of three nodes for each
input node, and I know in advance which kind they might be, so I simply
appended a dash and a three-letter code to the return value of generate-id().
That way, even though the output of generate-id() doesn't change with
multiple calls from the same context node, the value stored in the each
element's id attribute will be unique.

-- 
Charles Knell
cknell@xxxxxxxxxx - email


---- "Charles Knell" <cknell@xxxxxxxxxx> wrote:
> 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])"
> />
>      

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


Current Thread