Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > keys break when using node-set function

Reply
Thread Tools

keys break when using node-set function

 
 
Andy Chambers
Guest
Posts: n/a
 
      03-07-2008
Hi,

I've stumbled across a problem for which I can't find a nice solution
(although it has cleared up a misunderstanding I had about keys).

I've setup keys to access ItemDefs in my document like so...

<xsl:key name="keyItems"
match="odm:ItemDef"
use="concat(ancestor:dm:Study/@OID,
ancestor:dm:MetaDataVersion/@OID, @OID)"/>

Subsequently, I need to build a nodelist of strings with which I can
use to access nodes from this key

<xsl:variable name="xrtFormItems">

<xsl:for-each select="$xnlItemGroups">
<xsl:variable name="xndItemGroupDef"
select="key('keyItemGroups',
concat(ancestor:dm:Study/@OID,
ancestor:dm:MetaDataVersion/
@OID,
@ItemGroupOID))"/>

<xsl:for-each select="$xndItemGroupDef/odm:ItemRef">
<key>
<xsl:value-of select="concat(ancestor:dm:Study/
@OID,

ancestor:dm:MetaDataVersion/@OID,
@ItemOID)"/>
</key>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>

However, if I try to use the values stored in this variable to access
ItemDefs from my key....

<xsl:for-each select="ex:node-set($xrtFormItems)/*">
<xsl:apply-templates select="key('keyItems', .)"/>
</xsl:for-each>

....the key doesn't work. I thought that keys were basically a
hashtable that stored the specified nodes with the use attribute
representing the key. The point being that they were created at the
start and didn't change throughout the process. It seems that doing a
for-each on a node-set returned by some extension function can indeed
change the contents of your keys. Has anyone else bumped into this?
Is it a FAQ? What's the workaround?

--
Andy

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-07-2008
Andy Chambers wrote:

> However, if I try to use the values stored in this variable to access
> ItemDefs from my key....
>
> <xsl:for-each select="ex:node-set($xrtFormItems)/*">
> <xsl:apply-templates select="key('keyItems', .)"/>
> </xsl:for-each>
>
> ...the key doesn't work. I thought that keys were basically a
> hashtable that stored the specified nodes with the use attribute
> representing the key. The point being that they were created at the
> start and didn't change throughout the process. It seems that doing a
> for-each on a node-set returned by some extension function can indeed
> change the contents of your keys. Has anyone else bumped into this?
> Is it a FAQ? What's the workaround?


If you look at <URL:http://www.w3.org/TR/xslt#key> then it says: "A
stylesheet declares a set of keys for each document using the xsl:key
element."
So keys are built for each document and as the nodes you get from
ex:node-set are not part of the same document as the nodes in the input
document your approach above fails.
As a workaround might want to store values in a variable e.g.

<xsl:variable name="main-doc" select="/">

<xsl:for-each select="ex:node-set($xrtFormItems)/*">
<xsl:variable name="el" select="."/>
<xsl:for-each select="$main-doc">
<xsl:apply-templates select="key('keyItems', $el)"/>
</xsl:for-each>
</xsl:for-each>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
`if (!p ? i++ : 0) break;' == `if (!p){ i++; break;}' ? lovecreatesbea...@gmail.com C Programming 12 04-14-2008 07:59 AM
How to link foreign keys & primary keys using python? Harry George Python 9 06-13-2006 06:29 AM
can std::set hold pointers to keys instead of the keys themselves? danibe@my-deja.com C++ 10 02-03-2006 03:44 AM
serial keys/validation keys sandeep Kanwal C++ 1 10-29-2004 06:36 PM
keyboard keys replacing mouse keys? larry Computer Support 8 09-14-2003 07:32 PM



Advertisments