查找值 = X 的任何元素并报告根路径

Find any element whose value = X and report path to root

我有这样的数据:

<people>
    <person id="1">
        <july>busy</july>
    </person>
    <person id="2">
        <july>
            <Fridays>busy</Fridays>
        </july>
    </person>
    <person id="3">
        <july>
            <Fridays>
                <afternoons>busy</afternoons>
            </Fridays>
        </july>
    </person>
</people>

我想找到所有 text = 'busy' 的元素,然后将它们的路径报告回根。

我什至还没有找到如何只打印元素的方法。

//[text() = "busy"]

给予

[false()]
[false()]
[false()]
[true()]
[false()]
[false()]
[false()]
[true()]
[false()]
[false()]
[false()]
[false()]
[true()]
[false()]
来自 Martin Honnen 的

//*[. = 'busy']!path() 非常接近!

/Q{}people[1]/Q{}person[1]
/Q{}people[1]/Q{}person[1]/Q{}july[1]
/Q{}people[1]/Q{}person[2]
/Q{}people[1]/Q{}person[2]/Q{}july[1]
/Q{}people[1]/Q{}person[2]/Q{}july[1]/Q{}Fridays[1]
/Q{}people[1]/Q{}person[3]
/Q{}people[1]/Q{}person[3]/Q{}july[1]
/Q{}people[1]/Q{}person[3]/Q{}july[1]/Q{}Fridays[1]
/Q{}people[1]/Q{}person[3]/Q{}july[1]/Q{}Fridays[1]/Q{}afternoons[1]

我想我更喜欢只显示每个人最长路径的东西?我对 Q{} 并不着迷,但它的优先级要低得多。

/Q{}people[1]/Q{}person[1]/Q{}july[1]
/Q{}people[1]/Q{}person[2]/Q{}july[1]/Q{}Fridays[1]
/Q{}people[1]/Q{}person[3]/Q{}july[1]/Q{}Fridays[1]/Q{}afternoons[1]

我从你的评论中猜想你的解析器砍掉了 white-space 所以你想要 //*[not(*) and . = 'busy']!path(),以确保你只是 select 叶元素。