How to correctly concatenate XPath?

90 Views Asked by At

I try to match multiple elements and all their occurences through concatenation.

I tried two expressions

concat(//h5,'###',//h5/following-sibling::p)
concat(//*/h5,'###',//*/h5/following-sibling::p)

but both work partly - they match only the first occurence.

What I'm doing wrong? What is the working way to match all occurences?

1

There are 1 best solutions below

0
On

The string([node-set]) function is - most probably - implicitly used when the argument is an expression like //*/h5 so

contact(//*/h5, "some")
could translate to
concat(string(//*/h5), "some").

From string() doc:

If the object is a node-set, the string value of the first node in the set is returned.

To answer OP's question

What I'm doing wrong? What is the working way to match all occurences?

Nothing wrong per se, it's just many XPath 1.0 function operate only on the first element of a node set.

Those node sets should be iterated externally.