如何将静态值与Xpath Query结合使用
以下是我的XML数据
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
使用以下Xpath查询,我可以实现节点名称
的值1) breakfast_menu/food[not(name=preceding-sibling::food/name)]/name
Out Put:
Belgian Waffles
Strawberry Belgian Waffles
我的意图是将值'ALL'附加到输出。
下面的Xpath查询是我的研究使用Union Operator来实现
1) breakfast_menu/food[not(name=preceding-sibling::food/name)]/name | //food[name="ALL"]
使用Xpath例外输出:
ALL
Belgian Waffles
Strawberry Belgian Waffles
答案 0 :(得分:1)
假设您确实拥有XPath 2.0:
string-join(('ALL', distinct-values(breakfast_menu/food/name)), '\n')
将生成一个包含行
的字符串ALL
Belgian Waffles
Strawberry Belgian Waffles
如果你想要一系列字符串,那么只需使用
'ALL', distinct-values(breakfast_menu/food/name)