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'm trying to format and combine this into one line using xpath. Something like:
string-join(//ns2:Creator/concat(./text(), @Role), ', ')
I think, i'm somewhere close, because this:
string-join(//ns2:Creator/@Role , ', ')
works and gives me a comma-separated list of roles: Role1, Role2, Role3
and this
string-join(//ns2:Creator/node(), ', ')
combines the values of creators: "Creator One, Creator Two, Creator Three".
I'd like the final output of
Role1: Creator One, Role2: Creator Two, Role3: Creator Three
Could you please help.
You need to select
@Role
as the first parameter to your call toconcat()
, and use.
to select the string value of the context node:Instead of
.
you can also usestring()
orstring(.)
which makes explicit the conversion that would otherwise happen implicitly:Returns: