xml - Join multiple concatenations of attributes with node values using xpath -


i have 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 format , combine 1 line using xpath. like:

string-join(//ns2:creator/concat(./text(), @role), ', ') 

i think, i'm somewhere close, because this:

string-join(//ns2:creator/@role , ', ') 

works , gives me comma-separated list of roles: role1, role2, role3

and this

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

combines values of creators: "creator one, creator two, creator three".

i'd final output of

role1: creator one, role2: creator two, role3: creator 3 

could please help.

you need select @role first parameter call concat(), , use . select string value of context node:

string-join($xml//ns2:creator/concat(@role, ': ', .), ', ') 

instead of . can use string() or string(.) makes explicit conversion otherwise happen implicitly:

string-join($xml//ns2:creator/concat(@role, ': ', string(.)), ', ') 

returns:

role1: creator one, role2: creator two, role3: creator 3 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -