简体   繁体   中英

xslt get node-set text with key function

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM