我想使用 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 感到抱歉。