我有如下输入请求
<Input>
<BIKey></BIKey>
<BusinessObjects>
<BusinessObject>
<BusinessIdentifiers>
<BusinessIdentifier>
<BKey>BuCode</BKey>
<BValue>CDC</BValue>
</BusinessIdentifier>
<BusinessIdentifier>
<BKey>BuType</BKey>
<BValue>123</BValue>
</BusinessIdentifier>
<BusinessIdentifier>
<BKey>CsmNo</BKey>
<BValue>857895</BValue>
</BusinessIdentifier>
</BusinessIdentifiers>
<BusinessAttributes>
<BusinessAttribute>
<BKey>Version</BKey>
<BValue>1</BValue>
</BusinessAttribute>
<BusinessAttribute>
<BKey>date</BKey>
<BValue>2018-06-28</BValue>
</BusinessAttribute>
</BusinessAttributes>
</BusinessObject>
<BusinessObject>
<BusinessIdentifiers>
<BusinessIdentifier>
<BKey>BuCode</BKey>
<BValue>CDC</BValue>
</BusinessIdentifier>
<BusinessIdentifier>
<BKey>BuType</BKey>
<BValue>123</BValue>
</BusinessIdentifier>
<BusinessIdentifier>
<BKey>CsmNo</BKey>
<BValue>34567</BValue>
</BusinessIdentifier>
</BusinessIdentifiers>
<BusinessAttributes>
<BusinessAttribute>
<BKey>Version</BKey>
<BValue>1</BValue>
</BusinessAttribute>
<BusinessAttribute>
<BKey>date</BKey>
<BValue>2018-06-28</BValue>
</BusinessAttribute>
</BusinessAttributes>
</BusinessObject>
</BusinessObjects>
</Input>
并且我想让<BIKey>
的值应该是<BValue>
中所有<BusinessObject>
的值,并用':'隔开
对于上面的示例,<BIKey>
值应如下所示填充
<BIKey>CDC:123:857895:1:2018-06-28</BIKey>
<BIKey>CDC:123:34567:1:2018-06-28</BIKey>
我尝试过如下操作
<BIKey>
{
string-join(
for $bo in Input/BusinessObjects/BusinessObject return string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, '|'),
':'
)
}
</BIKey>
但是我没有满足确切的要求。请提出如何进行。
谢谢
答案 0 :(得分:0)
看起来就是您想要的:
for $bo in Input/BusinessObjects/BusinessObject return <BIKey>{string-join($bo//BValue, ':')}</BIKey>
您可以try it here。
您的XQuery代码存在以下问题:
<BIKey>
,而您期望每个BusinessObject
=>将<BIKey>
标签移到FLWOR的return
中,而不是移到标签外string-join
使用|
作为分隔符BValue
内的BusinessIdentifier
s,但您也希望加入BusinessAttribute
s内的那些人