3 functions XQuery, substring-before, substring-afterand tokenizeare used to obtain the desired output.
substring-before used to get the name.
Similarly, it is substring-afterused to receive a task.
The function tokenizeis then used to separate tasks.
let $data :=
<E>
<Employee>AAA@A#B#C#D</Employee>
<Employee>BBB@A#B#C#D</Employee>
<Employee>CCC@A#B#C#D</Employee>
<Employee>DDD@A#B#C#D</Employee>
</E>
for $x in $data/Employee
return
<Employee>
{<Name>{substring-before($x,"@")}</Name>}
{<Jobs>{
for $tag in tokenize(substring-after($x,"@"),'#')
return
<Job>{$tag}</Job>
}</Jobs>
}</Employee>
NTN ...
source
share