Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSLT选择整个文档中的最后一个元素_Xslt_Xpath_Xslt 2.0_Saxon - Fatal编程技术网

使用XSLT选择整个文档中的最后一个元素

使用XSLT选择整个文档中的最后一个元素,xslt,xpath,xslt-2.0,saxon,Xslt,Xpath,Xslt 2.0,Saxon,我想在文档中的任意位置选择与特定模式匹配的最后一个节点 我在尝试类似的东西 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:copy-of select="//node_name[last()]"/> </xsl:template> </xsl:style

我想在文档中的任意位置选择与特定模式匹配的最后一个节点

我在尝试类似的东西

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:copy-of select="//node_name[last()]"/>
  </xsl:template>
</xsl:stylesheet>

但是,在以下文档中使用Saxon 9.4运行此功能时:-

<a>
  <node_name attr="1"/>
  <b>
    <c>
    </c>
    <node_name attr="2"/>
  </b>
</a>

我在copy语句所在的位置获得此输出:-

<node_name attr="1"/><node_name attr="2"/>

而我实际上想要输出:-

<node_name attr="2"/>

我错过了什么


此外,我的文档的性质是,我事先不知道该节点的确切路径(因为它由一组递归元素组成)。

您不是在寻找最后一个
节点名称,而是在寻找所有节点名称中的最后一个。因此,以下XPath表达式应该可以工作:

(//node_name)[last()]