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).
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 thematch
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).