嵌套有效负载XML的Xquery

时间:2018-09-14 08:05:46

标签: xquery

这是我的输入XML:

这是我修改后的xml数据作为输入

JournalPage

我想将以下输出let vc = self.storyboard?.instantiateViewController(withIdentifier: “identifierier”) as! JournalPage vc.delegate = self // you need to call this delegate self.navigationController?.pushViewController(notifDetailVCObj, animated: true) 分配给 <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>

我已经按照Martin的建议尝试了Xquery,它实际上解决了我的查询器问题,但与先前的问题相比,我的inputpayload更大:

CDC|123|857895:CDC|123|34567

但是我得到了这个输出

<BIKey>

请协助解决此问题,因为我不确定在哪里循环有效负载以获取所需的输出。

谢谢

1 个答案:

答案 0 :(得分:0)

只需两次使用string-join,一个呼叫嵌套到另一个呼叫中:

<BIKey>
{
    string-join(
        Input/BusinessObjects/BusinessObject ! string-join(BusinessIdentifiers/BusinessIdentifier/BValue, '|'),
        ':'
    )
}
</BIKey>

通过这种方式,外部string-join会以小写分隔的字符串的顺序连接在一起,内部Input/BusinessObjects/BusinessObject ! string-join(BusinessIdentifiers/BusinessIdentifier/BValue, '|')会以冒号返回。

示例https://xqueryfiddle.liberty-development.net/eiQZDbi

如果您没有XQuery 3或更高版本,则可以将!的使用替换为

<Input>
    <BIKey>
    {
        string-join(
            for $bo in Input/BusinessObjects/BusinessObject return string-join($bo/BusinessIdentifiers/BusinessIdentifier/BValue, '|'),
            ':'
        )
    }
    </BIKey>
</Input>

https://xqueryfiddle.liberty-development.net/eiQZDbi/2