简体   繁体   English

Eclipse Xquery用于复杂有效负载

[英]Eclipse Xquery For Complex payload

I have the input request like below 我有如下的输入请求

 <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>

i have tried below Xquery to get the same but ended up with errors or not meeting the requiremnt 我曾尝试在Xquery下面获得相同的结果,但最终出现错误或不符合要求

<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>

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 '|' 输出字段的描述如下所示: BIKey >它由“ Business Identifier”的所有Bvalue组成,并以“:”连接,然后对于每个业务对象,将其以“ |”分隔。 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. Bkey - >直与BKEY映射Bvalue >与Bvalue直映射- BOID - >它已经形成的每个BusinessObject的,需要连接的价值观与企业标志的Bvalues“:”有什么建议,我相信我有这里有两个复杂的循环,但无法破解。

Thanks for @Martin as he helped me to crack this using ' ancestor ' axis, but some how eclispe is not identifying ' ancestor '. 感谢@Martin,因为他帮助我使用' ancestor '轴破解了这个问题,但是eclispe如何无法识别' ancestor '。

Thanks 谢谢

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. BIKey对于所有输出都是相同的,因此我们可以在任何循环之外进行计算并完成它。 We do so by joining all the BValues of a BusinessObject with : , and joining the result of this for each BusinessObject with | 为此,我们使用:将一个BusinessObject的所有BValue联接在一起,并使用|每个BusinessObject的结果联接在一起| :

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

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 : BOID将取决于我们正在处理的BusinessObject,因此我们需要遍历这些对象,然后可以在此时提取BOID:

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

The rest of the output fields depend on the BusinessIdentifier, so let's loop on these too and return a BusinessObject per BusinessIdentifier : 其余的输出字段取决于BusinessIdentifier,因此让我们也对它们进行循环,并为每个BusinessIdentifier返回一个BusinessObject:

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>

Now all we need is to wrap those output BusinessObjects into their parent tags : 现在,我们所需要做的就是将这些输出BusinessObjects包装到其父标记中:

<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>

You can test it here . 您可以在这里进行测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM