Reputation: 159
How to union Static values with Xpath Query
Below is my XML Data
<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>
With below Xpath queries, i can able to achieve the values of Node Name
1) breakfast_menu/food[not(name=preceding-sibling::food/name)]/name
Out Put:
Belgian Waffles
Strawberry Belgian Waffles
My Intention is to Append the value 'ALL' to the output.
below Xpath queries are my work outs Using Union Operator to achieve
1) breakfast_menu/food[not(name=preceding-sibling::food/name)]/name | //food[name="ALL"]
Excepted Out Put with Xpath:
ALL
Belgian Waffles
Strawberry Belgian Waffles
Upvotes: 0
Views: 1031
Reputation: 167676
Assuming you really have XPath 2.0:
string-join(('ALL', distinct-values(breakfast_menu/food/name)), '\n')
will yield a single string with lines
ALL
Belgian Waffles
Strawberry Belgian Waffles
If you want a sequence of strings then simply use
'ALL', distinct-values(breakfast_menu/food/name)
Upvotes: 2