我有一个包含 5 篇文章的 XML,每篇文章:
<root>
<article>
<c0>
<number>
</number>
<price>
</price>
</c0>
<c1>
<name> NewArtc1
</name>
<nameUs>TheBest
</nameUs>
</c1>
<c2>
<name> c2_1
</name>
<nameUs>NotTheBest
</nameUs>
</c2>
<c2>
<name> c2_2
</name>
<nameUs>TheBest
</nameUs>
</c2>
<c2>
<name> c2_3
</name>
<nameUs>NotTheBest
</nameUs>
</c2>
<c2>
<name> c2_4
</name>
<nameUs>TheBest
</nameUs>
</c2>
<c2>
<name> c2_5
</name>
<nameUs>NotTheBest
</nameUs>
</c2>
</article>
<article> ...
</root>
每个项目都有几个特征(c0、c1、c2 等)。我需要使用 XQuery (FLWOR) 返回 c1 的名称。后跟 c2 的名称,其 nameUs 节点的文本与 nameUs 节点 c1 的文本匹配(每篇文章有 5 个 c2) 对于每篇文章,输出格式应为:
<c1>
<name>NewArtc1</name>
<c2s>c2_2 c2_4</c2s>
</c1>
<c1>
<name>NewArtc2</name>
<c2s>c2_3 c2_5</c2s>
</c1>
请帮助我:/我已经这样做了,但它返回对,而不是我需要的输出格式:
for $a in doc("articles.xml")//article, $i in 1 to 5
let $b:=$a/c1/nameUs
let $c:=$a/c2[$i]/nameUs
where $b/text() and $b/text()=$c/text()
return <c1>{$b/name}<c2>{$c/name/text()}</c2></c1>