I need to add an attribute to an element of my response XML using XQuery. Take the below XML as input,
<xyz:RootNode xmlns:abc="url1" xmlns:xyz="url2">
<abc:OtherNodes/>
<abc:messageHeader att1="val1" att2="val2">
<abc:childNodes/>
</abc:messageHeader>
<abc:OtherNodes/>
</xyz:RootNode>
Need an Xquery that add one more attribute newAtt with value newVal and give the result as,
<xyz:RootNode xmlns:abc="url1" xmlns:xyz="url2">
<abc:OtherNodes/>
<abc:messageHeader att1="val1" att2="val2" newAtt="newVal">
<abc:childNodes/>
</abc:messageHeader>
<abc:OtherNodes>
</xyz:RootNode>
Each time the number of attributes of message header may change. So the query should add a new attribute along with all the existing attributes and return the whole document.
Try the following:
You then call foo:process-node on the RootNode