在我的 xml 文件中
<a>
<test id="bk1">
<go>B</go>
<from>A</from>
<test/>
<test id="bk2">
<go>C</go>
<from>D</from>
<test/>
<test id="bk2">
<go>D</go>
<from>E</from>
<test/>
</a>
所以我想选择 go 和 from 值并创建一个元素调用 $elements
预期输出:
<city>A</city>
<city>B</city>
<city>C</city>
<city>D</city>
<city>E</city>
在我的 xquery 查询中:
for $a in /a/test
for $elements in distinct-values($go) //How to add from into elements ?
return
<city>
{$elements}
</city>
最佳答案
for $a in distinct-values(/a/test/(go|from))
return <city>{ $a }</city>
关于xml - 具有不同子句的多个元素的 Xquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24123241/