0

我想使用 XPath 1.0 从重复父元素中选择不同的子元素。以下是 XML:

<parent>
<something>
    <catalog>
        <title>AAA</title>
        <artist>111</artist>
    </catalog>
    <catalog>
        <title>AAA</title>
        <artist>111</artist>
    </catalog>
    <catalog>
        <title>BBB</title>
        <artist>222</artist>
    </catalog>
</something>
<something>
    <catalog>
        <title>CCC</title>
        <artist>333</artist>
    </catalog>
    <catalog>
        <title>BBB</title>
        <artist>222</artist>
    </catalog>
    <catalog>
        <title>CCC</title>
        <artist>333</artist>
    </catalog>
</something>
<something>
    <catalog>
        <title>AAA</title>
        <artist>111</artist>
    </catalog>
    <catalog>
        <title>BBB</title>
        <artist>222</artist>
    </catalog>
    <catalog>
        <title>CCC</title>
        <artist>333</artist>
    </catalog>
</something>
</parent>

现在,在预期的输出中,我只想catalog在整个 XML 中挑选不同的元素,以便进一步处理它。所以输出应该是:

<catalog>
    <title>AAA</title>
    <artist>111</artist>
</catalog>
<catalog>
    <title>BBB</title>
    <artist>222</artist>
</catalog>
<catalog>
    <title>CCC</title>
    <artist>333</artist>
</catalog>

我查看了一些现有的解决方案,例如not(. = ../following-sibling::*),但这对我没有帮助,因为我试图在重复的父项中选择不同的项。请帮助并为令人发指的 xml 感到抱歉。

4

1 回答 1

1

使用跟随轴而不是跟随兄弟,它将搜索从当前上下文开始的所有文档:

//catalog[not(. = following::catalog)]
于 2013-06-12T07:39:24.097 回答