0

我正在尝试将 XPath 应用于具有以下结构的 XML 文件:

XPath:/root/tour/round/event/parent::round/@name

预期的输出是:

final
semifinal
semifinal
quarterfinal
quarterfinal
quarterfinal
quarterfinal
round3

但我没有得到上述输出,而是这样:

final
semifinal
quarterfinal
round3

对于获得预期输出的任何帮助,我将不胜感激。

XML 文件

<root>
    <tour>
        <round name="final">
            <event>Test</event>
        </round>
        <round name="semifinal">
            <event>Test</event>
            <event>Test</event>
        </round>
        <round name="quarterfinal">
            <event>Test</event>
            <event>Test</event>
            <event>Test</event>
            <event>Test</event>
        </round>
        <round name="round3">
            <event>Test</event>
            <event>Test</event>
            <event>Test</event>
            <event>Test</event>
        </round>
    </tour>
</root>
4

1 回答 1

1

您需要使用 XPATH 条件放置循环:

for $eachEvent in //event return $eachEvent/parent::round/@name
于 2013-05-22T10:17:41.897 回答