2016-06-15 4 views
0

値の例として、このxmlファイルを取る: -は、属性名とともにXPathを取得し、

<xyz version="1.0"> 
    <lives> 
     <life key="1"> 
     <section name="Application123"> 
     <disclosure type="alcohol"> 
    <disclosure type="build"> 
    <internal> 
    <height> data </height> 
    <weight>data</weight> 
    </internal> 
    </disclosure> 
    <disclosure type="drug"> 
    <disclosure type="tobacco"> 
    </section> 
    </life> 
    </lives> 
    </xyz> 

を、私は私の属性名と属性値と一緒にパスを与えるクエリをしたいです。仮定 、私は次のように私はすべてのパスをしたい、「構築」について照会: -

xyz/lives/life[key="1"]/section[name="Application123"]/disclosure[type="build"]/internal/height 

は、私は次のように

declare function local:path-to-node($nodes as node()*) as xs:string* { 
         $nodes/string-join(ancestor-or-self::*/name(.), ''/'') 

(XQueryで働く)を使用してパスを取得することができています:

xyz/lives/life/section/disclosure/internal/height 

しかし、属性名とその値も含まれている必要があります。 どのような提案の友人ですか?

答えて

0

XPathでは、属性の前には@が必要です。

xyz/lives/life[@key='1']/section[@name='Application123']/disclosure[@type='build']/internal/height 
関連する問題