简体   繁体   中英

XQUERY: Create elements with given names and values

I've a requiremnet to generate dynamic elements and values based on two xmls. How can I achieve using XQUERY.

I have data like in two xmls:

<td>USERID</td>
<td>NAME</td>
<td>RATING</td>

<id>1</id>
<name>Tom</name>
<grade>A</grade>

Expected:

<userid>1</userid>
<name>Tom</name>
<rating>A</rating>

The key here is the dynamic element constructor:

let $names  := (<td>USERID</td>, <td>NAME</td>, <td>RATING</td>)
let $values := (<id>1</id>, <name>Tom</name>, <grade>A</grade>)
for $name at $pos in $names
return
  element { fn:lower-case($name) } { fn:data($values[$pos]) }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM