XPath Axes - 用父节点的属性值替换父节点下子节点的'text'值

时间:2013-05-22 10:07:12

标签: xml xpath axes

我正在尝试将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>

1 个答案:

答案 0 :(得分:1)

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

for $eachEvent in //event return $eachEvent/parent::round/@name