1

absolute newbie who needs a quick answer (I'm going to research this tonight, but need an answer for now). Apologise in advance for idiocy:

I have written an xpath as follows:

sum(aaa[status='X' and code='Y']/value)

This does exactly what I want. However, aaa lives inside a couple of other nodes in the below format:

fff xmlns="urn:xxx.co.uk/soap:xxx" id="xxx"

ggg type="1" ... title="ASDGHJAS ASHD"

Why doesn't:

sum(fff/ggg/aaa[status='X' and code='Y']/value) work?

What do I have to do to tell it to look at node fff and ggg? I can't type the full name with all the items that come after the initial name as they are different every time the query runs.

Thanks if you can help a useless first timer!

<fff xmlns="urn:xxx.co.uk/soap:xxx" id="xxx" linktype="0"> 
 <ggg type="1" title="ABC"> 
  <aaa>
   <status>X</status> 
   <code>Y</code>
   <value>15</value> 
  </aaa>
 <aaa>
  <status>Z</status> 
  <code>G</code> 
  <value>5</value> 
 </aaa>
 <aaa> 
  <status>X</status> 
  <code>Y</code> 
  <value>30</value> 
 </aaa> 
</ggg> 

Rebecca
  • 11
  • 3

1 Answers1

0

Your XPath does not take into account the default namespace. See How does XPath deal with XML namespaces? and define a namespace prefix for the default namespace. In your specific case, define the following namespace,

x=urn:xxx.co.uk/soap:xxx

Then this XPath,

sum(//x:aaa[x:status='X' and x:code='Y']/x:value)

will return the answer of

45

as expected

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thanks for your help and not just abusing me for my basic knowledge. The linked question is very helpful, though I'm still a bit stuck. I'm going to admit defeat for now until my developer husband gets home. I was trying to do it myself - though you guys have done the majority! – Rebecca Jun 15 '17 at 12:36