2016-04-09 12 views
0

Response XMLで特定のノードを探し、条件に一致するかどうかによってtrueまたはfalseを返したいとします。一意のノード応答だけを受け取るために、XMLに含まれる要素と同じくらい多くを受け取らないようにするにはどうすればよいですか?ここでXMLのXqueryの取得要素から1つの応答しか取得しない

は私のXQueryコードです:このコードで

for $recordRetrieved in $sA_ADS_VerifOutput1/ns0:recordRetrieved 
     return 
      if ($recordRetrieved/ns0:COD_NRBE_EN = $ent and 
       $recordRetrieved/ns0:DAT <= $dat) 
      then <ns2:func>{ true() }</ns2:func> 
      else <ns2:func>{ false() }</ns2:func 

、XMLは、3つの要素が含まれている場合$sA_ADS_VerifOutput1/ns0:recordRetrieved応答は、(例えば)になります。

<ns2:func>false</ns2:func> 
<ns2:func>false</ns2:func> 
<ns2:func>true</ns2:func> 

私はこれをしたくありませんしかし、すべてが偽であるならば、私は<ns2:func>false</ns2:func>を期待しています。もし少なくとも1つが真実なら、私は<ns2:func>true</ns2:func>を1回だけ期待します。

私はwhere句を使用することを考えましたが、条件を満たすエレメットがなければfalseにする必要があります。

ありがとうございました。

答えて

5

あなたが欲しい:

some $recordRetrieved in $sA_ADS_VerifOutput1/ns0:recordRetrieved 
    satisfies ($recordRetrieved/ns0:COD_NRBE_EN = $ent and 
       $recordRetrieved/ns0:DAT <= $dat) 

以上単に

exists($sA_ADS_VerifOutput1/ns0:recordRetrieved[ 
     ns0:COD_NRBE_EN = $ent and ns0:DAT <= $dat]) 
+0

ありがとうございました!これは素晴らしいことです。 –

1

fn:distinct-values()を使用して重複を除去し、必要な要素にラップすることができます。

fn:distinct-values(
    for $recordRetrieved in $sA_ADS_VerifOutput1/ns0:recordRetrieved 
    return 
     if ($recordRetrieved/ns0:COD_NRBE_EN = $ent and 
      $recordRetrieved/ns0:DAT <= $dat) 
     then true() 
     else false() 
) ! <ns2:func>{.}</ns2:func> 
関連する問題