Google表格XPath查询XML命名空间[重复]

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

我正在尝试检索以下示例中date元素的最后和最后一个条目:

<c:classroom>Classroom 1</c:classroom>
    <a:date>2018-03-01</a:date>
    <a:teacher>Ms Smith</a:teacher>
    <a:assistant>Sara</a:assistant>
    <a:student>Rose</a:student>
    <a:student>Kris</a:student>
    <a:student>Jane</a:student>
<c:classroom>Classroom 2</c:classroom>
    <a:date>2018-03-02</a:date>
    <a:teacher>Mr Jones</a:teacher>
    <a:assistant>Bob</a:assistant>
    <a:student>Mike</a:student>
    <a:student>Pat</a:student>
    <a:student>Rick</a:student>
<c:classroom>Classroom 1</c:classroom>
    <a:date>2018-03-05</a:date>
    <a:teacher>Ms Smith</a:teacher>
    <a:assistant>Sara</a:assistant>
    <a:student>Rose</a:student>
    <a:student>Kris</a:student>
    <a:student>Jane</a:student>
<c:classroom>Classroom 2</c:classroom>
    <a:date>2018-03-06</a:date>
    <a:teacher>Mr Jones</a:teacher>
    <a:assistant>Bob</a:assistant>
    <a:student>Mike</a:student>
    <a:student>Pat</a:student>
    <a:student>Rick</a:student>

使用//*[local-name() = 'date'][last()]几乎返回所有内容并使用//*[local-name() = 'date'][last()-1]失败。

有什么建议?

更新:此XPath查询用于Google表格。

xml xpath google-sheets xquery
1个回答
2
投票

试试这个XPath

(//*[local-name() = 'date'])[last() - position() &lt; 2]

这应该得到文档中的最后两个dates。

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