2016-05-18 10 views
1

Xqueryの設計に問題があります。 私のXMLは、ポケモンのデータベースのように見えます:イムがやろうとしxqueryを使用した要素内のコンサルティング要素

<species id="a0001"> 
     <name></name> 
     <description></description> 
     <type></type> 
     <type></type> (can have different types) 
     <type></type> 
     <attack> 
      <has-attack id="p01"/> 
      <has-attack id="p02"/> 
     </attack> 
     <evolution> 
      <species id="a0002"> 
       . 
       . 
       . 
       <evolution> 
        <species id="a0003"> 
             . 
             . 
             . 
        </species> 
       </evolution> 
      </species> 
      <species id="a0004"> 
       . 
       . 
       . 
      </species> 
     </evolution> 
</species> 

何を、タイプ「火」ですべての種を取得することです。

declare variable $tipo as xs:string := "Fire"; 

for $b in doc(".xml")/bd/species 
let $nattacks:= count ($b/attacks) 
    where $b/type= $type 
return <result> 
     {$b/@id} 
     {$b/name} 
     <na>{$nattacks}</na> 
     </result> 

しかし、私は任意のヘルプ 、「エボリューション」のラベル内の種にアクセスする方法を知りませんか? har7 @

+0

ずっと整然と可能性があり、それが唯一の第一の種のIDを私に示し= A0001 – aldonair92

+2

あなたは全体のXML内のすべての 'species'要素を見つけるために' // species'を使用することができます: 'doc("。xml ")//種族。その問題は何ですか? – har07

+0

ありがとう、私はあなたが/ /ドキュメント内のすべての要素を見つけるために使用できるか分からなかった。 – aldonair92

答えて

2

が正しいですが、それは

declare variable $local:tipo as xs:string := "Fire"; 

for $b in doc(".xml")//species[type = $local:tipo] 
return <result> 
    {$b/@id} 
    {$b/name} 
    <na>{count($b/attacks)}</na> 
    </result> 
+0

ありがとう、それは本当にずっときれいに見えます。 – aldonair92

+0

進化した種をHTML本文に戻したいのですか?私は出力を得る正しい方法を見つけるように思えない – aldonair92

関連する問題