[英]Union Static Value with in Xpath Query
如何使用Xpath查询合并静态值
以下是我的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查询,我可以实现Node Name的值
1) breakfast_menu/food[not(name=preceding-sibling::food/name)]/name
输出:
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
假设您确实拥有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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.