Xml Xquery中的双附加
我想附加一些XML标记的值,然后再次附加结果。但是我在附加结果时遇到了一些问题,所以我只有一个附加的最终结果 想象你有这样一个:Xml Xquery中的双附加,xml,join,append,xquery,Xml,Join,Append,Xquery,我想附加一些XML标记的值,然后再次附加结果。但是我在附加结果时遇到了一些问题,所以我只有一个附加的最终结果 想象你有这样一个: <nodeA> <nodeB> <item>1</item> <item>2</item> <yesno>blah</yesno> </nodeB> <nodeC> <thing>A</thing> </node
<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>
1.
2.
废话
A.
3.
4.
废话
B
我想得到这个结果A,1,2,B,3,4
但我得到了这个:A,1,2B,3,4
我一直在读这篇文章:但我还是不能让它工作。这是我的代码示例
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>
让$contador:=计数(
对于$productDoc/*[子字符串(本地名称(.),2,23)=“nodeB”]
不存在时(存在($x/ns0:yesno))
返回
$x)
返回
如果($contador=0),则
其他的
对于$productDoc/*[子字符串(本地名称(.),2,18)=“nodeB”]
不存在的地方(存在($x//ns0:yesno))
返回
对于$x中的$y/*[匹配项(名称(.),'thing')]
让$z:=$x/*[匹配(名称(.),'item')]
返回
以$y表示的$i
让$c:=concat($i,“,”,字符串连接($z,”))
返回
让$d:=字符串联接($c,“,”)
{$d}
我想发生的是我错误地附加了部分结果。。。或者在一个错误的地方,但我不知道在哪里做。也许我应该从另一个函数调用这个函数,该函数将结果进行字符串连接。您认为如何?以下查询将准确返回您需要的内容(在您提供的示例上运行):
{
串接(
对于$productDoc//nodeA中的$nodeA
返回($nodeA//thing,$nodeA//item),“,”)
}
如果您需要更具体的内容,请在问题中指定更多细节。最好给出一个XML示例以及您想要得到的结果。很难理解你想要什么只是查看你的代码。我认为示例的代码是可见的,我编辑它来更正它。非常感谢。我将您的查询添加到我的实际XML文件中,并且工作正常。我想我把事情弄得更复杂了。
<result>{
string-join(
for $nodeA in $productDoc//nodeA
return ($nodeA//thing, $nodeA//item), ",")
}</result>