Xquery 中的双重追加
我想附加一些 XML 标记的值,然后再次附加结果。但我在附加结果时遇到了一些麻烦,所以我只有一个最终的附加结果。
想象一下你有这样的情况:
<nodeA>
<nodeB>
<item>1</item>
<item>2</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>A</thing>
</nodeC>
</nodeA>
<nodeA>
<nodeB>
<item>3</item>
<item>4</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>B</thing>
</nodeC>
</nodeA>
我想得到这个结果
但我得到了这个:
我一直在读这个:XQuery:如何在 for 循环中正确附加 , 但我仍然不能让它发挥作用。这是我的代码示例。
let $contador := count(
for $x in $productDoc//*[substring(local-name(.),2,23)="nodeB"]
where not(exists ($x/ns0:yesno))
return
$x)
return
if ($contador = 0) then
<result> </result>
else
for $x in $productDoc//*[substring(local-name(.),2,18)="nodeB"]
where not(exists ($x//ns0:yesno))
return
for $y in $x//*[matches(name(.),'thing')]
let $z := $x//*[matches(name(.),'item')]
return
for $i in $y
let $c := concat($i,",",string-join($z,","))
return
let $d := string-join($c,",")
<result>{ $d }</result>
我想发生的事情是我错误地附加了部分结果......或者附加在错误的位置,但我不知道在哪里做。也许我应该从另一个对结果进行字符串连接的函数调用此函数。你觉得怎么样?
I want to append the values of some XML tags, and then append again the result. But I'm having some trouble appending the results, so I only have one final result of appending.
Imagine you have this:
<nodeA>
<nodeB>
<item>1</item>
<item>2</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>A</thing>
</nodeC>
</nodeA>
<nodeA>
<nodeB>
<item>3</item>
<item>4</item>
<yesno>blah</yesno>
</nodeB>
<nodeC>
<thing>B</thing>
</nodeC>
</nodeA>
I want to get this result <result>A,1,2,B,3,4</result>
But I get this one: <result>A,1,2</result><result>B,3,4</result>
I've been reading this: XQuery: how to properly append , in for loop but still I can't make it work. Here is the sample of my code.
let $contador := count(
for $x in $productDoc//*[substring(local-name(.),2,23)="nodeB"]
where not(exists ($x/ns0:yesno))
return
$x)
return
if ($contador = 0) then
<result> </result>
else
for $x in $productDoc//*[substring(local-name(.),2,18)="nodeB"]
where not(exists ($x//ns0:yesno))
return
for $y in $x//*[matches(name(.),'thing')]
let $z := $x//*[matches(name(.),'item')]
return
for $i in $y
let $c := concat($i,",",string-join($z,","))
return
let $d := string-join($c,",")
<result>{ $d }</result>
I suppose what is happening is that I'm appending the partial results wrongly... or in a wrong place, but I don't know where to do it. Maybe I should call this function from another one that makes a string-join of the result. What do u think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下查询准确返回您需要的内容(在您提供的示例上运行):
如果您需要更具体的内容,请在问题中指定更多详细信息。
The following query returns exactly what you need (running on example you provided):
Specify more details in your question if you need something more specific.