Eclipse Xquery用于复杂有效负载 [英] Eclipse Xquery For Complex payload

查看:49
本文介绍了Eclipse Xquery用于复杂有效负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下输入请求

 <Input>
    <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>
           </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>
            </BusinessObject>      
        </BusinessObjects>
        </Input>

我需要形成类似于以下架构的输出

i need to form an output like below schema

<Output>
<BusinessObject>
<BIKey></BIKey>
<BKey></BIKey>
<Bvalue></Bvalue>
<BOID></BOID>
</BusinessObject>
</Output>

对于上述有效负载输出应该是

For the above payload The output should be

  <Output>
    <BusinessObjects>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>BUCode</BKey>
    <Bvalue>CDC</Bvalue>
    <BOID>CDC:123:857895</BOID>
    </BusinessObject>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>BUtype</BKey>
    <Bvalue>123</Bvalue>
    <BOID>CDC:123:857895</BOID>
    </BusinessObject>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>CSMNo</BKey>
    <Bvalue>857895</Bvalue>
    <BOID>CDC:123:857895</BOID>
    </BusinessObject>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>BUCode</BKey>
    <Bvalue>CDC</Bvalue>
    <BOID>CDC:123:34567</BOID>
    </BusinessObject>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>BUtype</BKey>
    <Bvalue>123</Bvalue>
    <BOID>CDC:123:34567</BOID>
    </BusinessObject>
    <BusinessObject>
    <BIKey>CDC:123:857895|CDC:123:34567</BIKey>
    <BKey>CSMNo</BKey>
    <Bvalue>857895</Bvalue>
    <BOID>CDC:123:34567</BOID>
    </BusinessObject>
    </BusinessObjects>
    </Output>

我曾尝试在Xquery下获得相同的结果,但最终出现错误或不符合要求

i have tried below Xquery to get the same but ended up with errors or not meeting the requiremnt

<Ouput>
<BusinessObjects>
{
for $bi in Input/BusinessObjects/BusinessObject/BusinessIdentifiers/BusinessIdentifier
return
<BIKey>
    {
        string-join(
            for $bo in Input/BusinessObjects/BusinessObject return string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, '|'),
            ':'
        )
    }
    </BIKey>
    <BKey>data {$bi/Bkey}</BKey>
    <Bvalue>data {$bi/Bvalue}</Bvalue>
    for $bo in Input/BusinessObjects/BusinessObject return <BOID>{string-join($bo//BValue, ':')}<BOID>

}
</BusinessObjects>
</Ouput>

对输出字段的描述如下 BIKey ->已将业务标识符"的所有B值与:"连接在一起,然后对于每个业务对象,将其与"|"分隔 Bkey ->与bkey的直接映射 Bvalue ->使用Bvalue的直接映射 BOID ->必须为每个业务对象形成,需要将值的值以:"连接到业务标识符的Bvalues任何建议,我相信我必须在这里进行两个复杂的循环,但无法破解.

the description for the output fields as follows BIKey-->it has formed with all the Bvalues of 'Business Identifier' concatenated with ':' and then for each businessobject it is separed with '|' Bkey-->Straight mapping with bkey Bvalue-->Straight mapping with Bvalue BOID--> it has to formed for each businessobject, need to concatenate the values Bvalues of Business Identifiers with ':' Any suggestions, i believe that i have to two complex loops in here, but not able to crack it.

感谢@Martin,因为他帮助我使用' ancestor '轴破解了这个问题,但是eclispe如何无法识别' ancestor '.

Thanks for @Martin as he helped me to crack this using 'ancestor' axis, but some how eclispe is not identifying 'ancestor'.

谢谢

推荐答案

BIKey对于所有输出都是相同的,因此我们可以在任何循环之外进行计算并完成它.为此,我们将一个BusinessObject的所有BValue与:联接,并为每个BusinessObject的结果与 | :

The BIKey will be the same for all of the output, so we can compute it outside of any loop and be done with it. We do so by joining all the BValues of a BusinessObject with :, and joining the result of this for each BusinessObject with | :

let $BIKey := string-join(for $bo in /Input/BusinessObjects/BusinessObject return string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, ':'), '|')

BOID将取决于我们正在处理的BusinessObject,因此我们需要对它们进行循环,然后可以在此时提取BOID:

The BOID will depend on the BusinessObject we're handling, so we need to loop over those and we can extract the BOID at that point :

let $BIKEY := [...]
for $bo in /Input/BusinessObjects/BusinessObject
  let $BOID := string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, ':')

其余的输出字段取决于BusinessIdentifier,所以让我们也对它们进行循环,并为每个BusinessIdentifier返回一个BusinessObject:

The rest of the output fields depend on the BusinessIdentifier, so let's loop on these too and return a BusinessObject per BusinessIdentifier :

let $BIKEY := [...]
for $bo in [...]
  let $BOID :=  [...]
  return for $bi in $bo/BusinessIdentifiers/BusinessIdentifier/
    return <BusinessObject>
             <BIKey>{$BIKEY}</BIKey>
             <BKey>{$bi/BKey}</BKey>
             <Bvalue>{$bi/Value}</Bvalue>
             <BOID>{$BOID}</BOID>
           </BusinessObject>

现在我们所需要做的就是将这些输出BusinessObjects包装到其父标记中:

Now all we need is to wrap those output BusinessObjects into their parent tags :

<output><BusinessObjects>{
let $BIKEY := string-join(for $bo in /Input/BusinessObjects/BusinessObject return string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, ':'), '|')
for $bo in /Input/BusinessObjects/BusinessObject
  let $BOID := string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, ':')
  return
    for $bi in $bo/BusinessIdentifiers/BusinessIdentifier
    return <BusinessObject>
<BIKey>{$BIKEY}</BIKey>
<BKey>{$bi/BKey/text()}</BKey>
<Bvalue>{$bi/BValue/text()}</Bvalue>
<BOID>{$BOID}</BOID>
</BusinessObject>
}</BusinessObjects></output>

您可以在此处进行测试.

这篇关于Eclipse Xquery用于复杂有效负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆