Xquery for Nest和concat

问题描述 投票:0回答:1

这是我修改的输入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
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.