Search code examples
xpathxquerymarklogic

Xpath using get the Attribute value


I have mentioned the same XML in below .

XML :1

 <PP XML="2000_4_174.xml">
      <P name="Antony" value="IN"/>
      <P name="sitting" value="17 AUGUST 2000"/>
      <P name="type" value="reported"/>
      <P name="startpage" value="174"/>
      </PP>

XML :2

 <PP XML="2000_4_17411.xml">
  <P name="Antony" value="IN"/>
  <P name="sitting" value="17 AUGUST 2000"/>
  <P name="type" value="reported"/>
  <P name="startpage" value="1"/>
  </PP>

I have using different condition of in Xpath query for getting @XML value condition(@name ="Antony" and @value="IN" and @name ="startpage" and @value="174") so expect output is (2000_4_174.xml)

I have tried this Query please suggest me how to add the another two conditions.

let $uri :=  //PP/P[@name="Antony" and @value="IN"] 
for  $i in $uri
let $j := xdmp:node-uri($i)
let $s :=doc($j)/PP/@XML
return $s

Solution

  • XPath for that would be :

    //PP[P[@name="Antony" and @value="IN"] 
             and 
         P[@name="startpage" and @value="174"]
        ]/@XML
    

    The XPath should return XML attribute of <PP> element which contains the following child elements :

    <P name="Antony" value="IN"/>
    <P name="startpage" value="174"/>