0

Is it possible to access the textnode of a node-set with a key function in xslt 1.0? I have following code:

<xsl:variable name="Items">
        <Item ID="ID1">name1</Item>
        <Item ID="ID2">name2</Item>
</xsl:variable>

<xsl:key name="get_item_by_ID" match="exsl:node-set($Items)/Item" use="@ID"/>

<xsl:template match="/Items">
    <xsl:value-of select="key('get_item_by_ID', @ItemID)/text()"></xsl:value-of>
 </xsl:template> 

I want to search for the text of the node-set by the ItemID of the current Item, in order to rename the Item by it's predefined node-set text (ID1: name1, ID2: name2).

nh_
  • 299
  • 5
  • 25

1 Answers1

0

You have a context issue here:

The node-set created by exsl:node-set($Items) is a separate "document". You cannot specify the document to match within the match attribute of a <key> element.

You must switch the context to the desired document before you call the key() function (in XSLT 2.0 you can specify the document to match within the key() function itself).

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Thanks I didn't know this. What do you mena with "switch de context do the desired document"? How can I realize that? – nh_ Nov 17 '14 at 10:09
  • You can switch context by using `xsl:for-each`, for example ``. See an example of that in your previous question: http://stackoverflow.com/questions/26889758/xslt-node-set-use-in-key-function-find-children-by-parent-attribute – michael.hor257k Nov 17 '14 at 11:09