简体   繁体   English

xslt获取具有键功能的节点集文本

[英]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? 是否可以在xslt 1.0中使用键功能访问节点集的textnode? 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). 我想通过当前项的ItemID搜索节点集的文本,以便通过其预定义的节点集文本(ID1:name1,ID2:name2)重命名该项目。

You have a context issue here: 您在此处遇到上下文问题:

The node-set created by exsl:node-set($Items) is a separate "document". exsl:node-set($Items)创建的exsl:node-set($Items)是一个单独的“文档”。 You cannot specify the document to match within the match attribute of a <key> element. 您不能在<key>元素的match属性内指定要匹配的文档。

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). 在调用key()函数之前,必须将上下文切换到所需的文档(在XSLT 2.0中,您可以在key()函数本身内指定要匹配的文档)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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