Xml 如何提取值并在将来的xpath查询中使用它?

Xml 如何提取值并在将来的xpath查询中使用它?,xml,xslt,xpath,Xml,Xslt,Xpath,我将节点的值提取到变量中: <xsl:variable name="UPC" select="//x:input[@name='field-keywords']/@value"/> <xsl:value-of select="$UPC" /> <!-- This works! --> <xsl:variable name="UPC" select="//x:input[@name='field-keywords']/@value"/>

我将节点的值提取到变量中:

<xsl:variable name="UPC" select="//x:input[@name='field-keywords']/@value"/>
<xsl:value-of select="$UPC" />  <!-- This works! -->
 <xsl:variable name="UPC" select="//x:input[@name='field-keywords']/@value"/>

然后,我想为具有相同值的节点查询另一个XML文档:

<xsl:value-of select="document('price_list.xml')/im_prices/row/UPC_Code[text()='$UPC']"/>

当我用$UPC替换实际值时,我发现节点很好,但当我使用$UPC时,它不起作用


我还无法解决如何将值提取到变量中,并在将来的xpath查询中使用它。

只需删除撇号——在表达式中,您可以将其与文本“$UPC”进行比较:

 <xsl:value-of select=
   "document('price_list.xml')
        /im_prices/row/UPC_Code[text()=$UPC]"/>

即使删除了撇号,上面的代码也会输出
文档('price_list.xml')中第一个的字符串值/im_prices/row/UPC_Code元素具有文本节点子元素,其字符串值等于变量$UPC

中包含的其中一个节点的字符串值,只需删除撇号即可——在表达式中与文本“$UPC”进行比较:

 <xsl:value-of select=
   "document('price_list.xml')
        /im_prices/row/UPC_Code[text()=$UPC]"/>
Then I want to query another XML document for a node with the same value:

     <xsl:value-of select="document('price_list.xml')/im_prices/row/UPC_Code[text()='$UPC']"/>

即使删除了撇号,上面的代码也会输出
文档('price_list.xml')中第一个的字符串值/im_prices/row/UPC_Code元素有一个文本节点子元素,其字符串值等于变量$UPC

中包含的一个节点的字符串值。非常感谢您的详细解释,这非常有帮助,因为我没有真正弄清楚您提到的几个关键点。在这种情况下,UPC_代码是唯一的(我自己的知识),所以记下第一个这样的注释是可以的,但我很感激你指出,我跳过重复的UPC_代码节点是完全可行的。非常感谢你的详细解释,这对我很有帮助,因为我对你提到的几个关键点不太清楚。本例中的UPC_代码是唯一的(据我自己所知),所以记下第一个这样的注释是可以的,但我感谢您指出,我跳过重复的UPC_代码节点是完全可行的。
Then I want to query another XML document for a node with the same value:

     <xsl:value-of select="document('price_list.xml')/im_prices/row/UPC_Code[text()='$UPC']"/>