首页 > 解决方案 > 用于嵌套和连接的 Xquery

问题描述

这是我修改后的输入 XML:

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

我想将以下输出CDC|123|857895:CDC|123|34567分配给<BIKey>.

我试过这个 Xquery:

<Input>    
    <BIKey>{ string-join(data($Input/BusinessIdentifiers/BusinessIdentifier/BValue),'|') }</BIKey>
</Input>

但我得到了这个输出CDC|123|857895|CDC|123|34567

我怎样才能解决这个问题?

标签: xquery

解决方案


您使用了错误的功能,使用string-join(sequence, '|'),而不是concat例如

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

https://xqueryfiddle.liberty-development.net/948Fn5e


推荐阅读