My XML Response Load appears as below
<entries>
<id>1</id>
<UseCountIds>100</UseCountIds>
<UseCountIds>200</UseCountIds>
<UseCountIds>300</UseCountIds>
</entries>
此处&#39;条目&#39;是父节点,它具有子元素viz&#39; id&#39;,&#39; UseCountIds&#39;。上面的例子是id = 1。同样,有很多条目&#39;对于id = 2或id = 3等。
&#39; ID&#39;是一种独特的价值。
我已经完成了一个XQuery来从XML Payload中提取Child元素。以下是使用的Xquery
let $entries := /root/entries
return
for $entry in $entries
return
<entries>
{
$entry/id,
<UseCountIds>{data($entry/UseCountIds)}</UseCountIds>
}
</entries>
问题是,如果上面的XQuery输出加载到.csv文件中,它会显示为
id,UseCountIds
1,100 200 300
UseCountIds(多个值)出现在以空格分隔的列中。
我的要求是获得如下所需的输出
id,UseCountIds
1,100
1,200
1,300
此外,UseCountIds不仅限于3次出现。对于一个独特的ID&#39;可以有&#39; n&#39;没有。 of UseCountIds。
将UseCountIds连接到一个唯一的ID&#39;总是好的。在行级别。
请分享您的想法,如何调整XQuery以获得上述所需的输出。
谢谢, T G
答案 0 :(得分:0)
目前还不清楚如何从XQuery的输出生成CSV,但是,如果我可以假设您只需要为源XML中的每个entries
生成一个UseCountIds
元素要生成所需的CSV数据,那么这是一个可能的XQuery:
for $c in /root/entries/UseCountIds
return
<entries>
{
$c/preceding-sibling::id,
$c
}
</entries>
如果没有产生所需的输出,那么请发布XQuery输出应该如何。
即使没有孩子entries
,也能够返回UseCountIds
:
for $e in /root/entries
let $id := $e/id
let $useCountIds := $e/UseCountIds
return
if($useCountIds) then
for $c in $useCountIds
return
<entries>
{
$id,
$c
}
</entries>
else
<entries>
{
$id,
<UseCountIds></UseCountIds>
}
</entries>
<强> demo
强>