为什么last()选择以下XML中的两个标签?

问题描述 投票:0回答:1

给定以下 XML:

<app>
    <welcome-message>Hi! This is xpather beta...</welcome-message>
    <abstract>
        This web app enables you to query XML/HTML documents with your
        browser in real time. It can generate queries for you too! 
    </abstract>
    <description>
        <subject>
            To generate an xpath query for a specific element,
            please hold CTRL and hover over it.
            An xpath is generated heuristically with the aim
            to be unambiguous and the shortest possible.
        </subject>
      <note>hey</note>
    </description>
    <extra-notes>
        <note>
            By default XML mode is used but if a document cannot
            be parsed as XML then HTML mode kicks in.
        </note>
        <note>
            Pasting documents bigger than 500kb may cause your
            browser become sluggish or unresponsive.
        </note>
    </extra-notes>
</app>

以下 Xpath:

//note[last()]
返回两个标签:
<description>
中的最后一个标签和
<extra-notes>
中的最后一个标签。 但这是为什么呢? last() 是否不对前一个轴的节点集进行操作?
//note
应该给我们一组节点,从中我们应该能够选择最后一个。

xml xpath
1个回答
0
投票

使用

(//note)[last()]
descendant::note[last()]
,您的尝试将被评估为/是
/descendant-or-self::node()/note[last()]
的简写。

© www.soinside.com 2019 - 2024. All rights reserved.