XQuery中的请求转换带有出现的双重元素

时间:2018-08-12 17:10:09

标签: proxy request transform xquery osb

我正在尝试转换请求 我的样本包括以下部分:

<v13:Notes>
    <v13:Note>
        <v12:IDs>
            <v12:ID>1-12345</v12:ID>
        </v12:IDs>
        <v12:Type>Fixed</v12:Type>
        <v12:Categories>
            <v12:Category listName="Category">Internet</v12:Category>
            <v12:Category listName="SubCategory">Slow Speed</v12:Category>
        </v12:Categories>
        <v12:Content>new comments</v12:Content>
        <v12:AgentID>1-abcdef</v12:AgentID>
    </v13:Note>
    <v13:Note>
        <v12:IDs>
            <v12:ID>1-87654</v12:ID>
        </v12:IDs>
        <v12:Type>Fixed</v12:Type>
        <v12:Categories>
            <v12:Category listName="Category">kjhgf</v12:Category>
            <v12:Category listName="SubCategory">sdfcghj Speed</v12:Category>
        </v12:Categories>
        <v12:Content>new chjhmj,nm</v12:Content>
        <v12:AgentID>1-ilkol</v12:AgentID>
    </v13:Note>
</v13:Notes>
<v13:StatusHistory>
    <v12:StateTransition>
        <v12:ReasonCode>Pending</v12:ReasonCode>
        <v12:SubReasonCode>Pending</v12:SubReasonCode>
        <v12:Description>Incident</v12:Description>
    </v12:StateTransition>
    <v12:StateTransition>
        <v12:ID>1-12345</v12:ID>
        <v12:ReasonCode>fixed</v12:ReasonCode>
        <v12:SubReasonCode>fixed</v12:SubReasonCode>
        <v12:Description>Note</v12:Description>
    </v12:StateTransition>
</v13:StatusHistory>

在转换后的请求中,我必须包含以下部分:

<Interaction>
    <OwnedBy>1-abcdef</OwnedBy>
    <Area>Pending</Area>
    <SubArea>Pending</SubArea>
</Interaction>
<Interaction>
    <OwnedBy>1-ilkol</OwnedBy>
    <Area>fixed</Area>
    <SubArea>fixed</SubArea>
</Interaction>

但是我无法以期望的形式拥有它。 我使用:

{
                if($UpdateIncidentVBMRequest/v11:IncidentVBO/v13:Parts/v13:StatusHistory/v12:StateTransition/v12:Description/text() = 'Note') then
                (
                let $Note := $UpdateIncidentVBMRequest/v11:IncidentVBO/v13:Parts/v13:Notes/v13:Note
                return
                for $StateTransition in $UpdateIncidentVBMRequest/v11:IncidentVBO/v13:Parts/v13:StatusHistory/v12:StateTransition
                return
                    (
<Interaction>
                            {
                            for $AgendID in $Note/v12:AgentID
                            return
    <OwnedBy>{ data($AgendID) }</OwnedBy>
                            }
                            {
                            for $ReasonCode in $StateTransition/v12:ReasonCode
                                return
    <Area>{ data($ReasonCode) }</Area>
                            }
                            {
                            for $SubReasonCode in $StateTransition/v12:SubReasonCode
                                return
    <SubArea>{ data($SubReasonCode) }</SubArea>
                            }
                            {
                            for $Category in $UpdateIncidentVBMRequest/v11:IncidentVBO/v13:RelatedIncidents/v13:RelatedIncident/v12:Categories/v12:Category
                                return
    <OwnerGroup>{ data($Category) }</OwnerGroup>
                            }
</Interaction>
                    )
                )
                else()
                }

我的转换请求就是这个:

<Interaction>
    <OwnedBy>1-abcdef</OwnedBy>
    <OwnedBy>1-ilkol</OwnedBy>
    <Area>Pending</Area>
    <SubArea>Pending</SubArea>
</Interaction>
<Interaction>
    <OwnedBy>1-abcdef</OwnedBy>
    <OwnedBy>1-ilkol</OwnedBy>
    <Area>fixed</Area>
    <SubArea>fixed</SubArea>
</Interaction>

当我写的时候:

for $StateTransition in $UpdateIncidentVBMRequest/v11:IncidentVBO/v13:Parts/v13:StatusHistory/v12:StateTransition
                return

                    (
<Interaction>
                            {
                            for $Notes in $UpdateIncidentVBMRequest/v11:IncidentVBO/v13:Parts/v13:Notes
                            return
                            (<OwnedBy>{ data($Notes/v13:Note/v12:AgentID) }</OwnedBy>)
                            }

我提出以下建议:

<Interaction>
    <OwnedBy>1-abcdef 1-ilkol</OwnedBy>
    <Area>Pending</Area>
    <SubArea>Pending</SubArea>
</Interaction>
<Interaction>
    <OwnedBy>1-abcdef 1-ilkol</OwnedBy>
    <Area>fixed</Area>
    <SubArea>fixed</SubArea>
</Interaction>

所以我真的无法弄清楚为什么元素首先出现双倍,而在第二个示例中“以某种方式连接” 其他2个元素(区域,子区域按预期工作) 任何帮助将不胜感激!

提前谢谢!

1 个答案:

答案 0 :(得分:0)

首先,我认为获得所需答案的最简单方法是:

for $i in 1 to count(v13:Notes)
return
  <Interaction>
    <OwnedBy>{v13Note[$i]/v12:AgentID/data()}</OwnedBy>
    <Area>{v13:StatusHistory[$i]/v12:StateTransition/v12:ReasonCode/data()}</Area>
    <SubArea>{v13:StatusHistory[$i]/v12:StateTransition/v12:SubReasonCode/data()}</SubArea>
  </Interaction>

我可能在这里错过了您想要的逻辑中的某些内容,但是从无法正常工作的代码对需求进行逆向工程并不容易。

第二,您的代码未产生所需结果的原因是,您为<OwnedBy>中的每个元素编写了一个$Note/v12:AgentID元素,并且$Note被绑定到包含两个元素的序列v12:Note个元素;因此,您在每个<OwnedBy>

中写了两个<Interaction>元素