W.W
W.W

Reputation: 109

concat() in XPath

here is my xml :

<compositeurs> 
    <compositeur></compositeur>
    <compositeur id="5">
        <dates naissance="1687" deces="1770"></dates>
        <nom>
            <prenom>Johann</prenom>
            <prenom>Sebastian</prenom>
            <prenom>Sebastian</prenom>
            <prenom>Sebastian</prenom>
            <famille>Bach</famille>
        </nom>
    </compositeur> 
        <pays>Alemagne</pays>
    <compositeur></compositeur>
</compositeurs>

I would like to concat all the elements prenom that have famille="Bach".

I used concat(//nom[famille='Bach']/prenom) but its wrong.

Upvotes: 2

Views: 1599

Answers (1)

toniedzwiedz
toniedzwiedz

Reputation: 18563

It's not possible to do it in XPath 1.0

Here's the way to do it in XPath 2.0:

string-join(//nom[famille='Bach']/prenom, ' ')

If XPath 2.0 is unavailable, you can always concatenate the results of your original expression in whatever imperative language you're using.

Upvotes: 2

Related Questions