Attach multiple attribute concatenations using node values ​​using xpath

I have the following xml content:

<ns2:ItemAttributes xml:lang="de-DE">
    <ns2:Creator Role="Role1">Creator One</ns2:Creator>
    <ns2:Creator Role="Role2">Creator Two</ns2:Creator>
    <ns2:Creator Role="Role3">Creator Three</ns2:Creator>
</ns2:ItemAttributes>

I am trying to format and merge this into one line using xpath. Sort of:

string-join(//ns2:Creator/concat(./text(), @Role), ', ')

I think I'm somewhere nearby, because this:

string-join(//ns2:Creator/@Role , ', ')

works and provides a comma separated list of roles: Role1, Role2, Role3

and this one

string-join(//ns2:Creator/node(), ', ')

unites the values ​​of the creators: "One Creator, Two Creator, Three Creator."

I need a final conclusion

Role1: Creator One, Role2: Creator Two, Role3: Creator Three

Could you help me.

+1
source share
1 answer

You need to select @Roleas the first parameter for your call concat()and use .to select the string value of the context node:

string-join($xml//ns2:Creator/concat(@Role, ': ', .), ', ')

. string() string(.), , :

string-join($xml//ns2:Creator/concat(@Role, ': ', string(.)), ', ')

:

Role1: Creator One, Role2: Creator Two, Role3: Creator Three
0

Source: https://habr.com/ru/post/1660433/


All Articles