xpath and Expression must evaluate to a node-set

Jack Frillman

Usenet Archive
Joined
Apr 12, 2000
Messages
3
Reaction score
0
Below is an xpath that works. It returns all the values of the "value attribute" of the OutputField tag:

//Satellite/multidataset/file[contains(@name, '311multi')]/Data/ DriftAnalysis[contains(@name, '311')]/Metric[@name='Detail' and @type='Overlap']/Element[@metrictype='Overlap']/ OutputField[@name='Cleared']/@value

But when I try to sum the returned values of the "value attribute" using the sum function like the example below I get the error "Expression must evaluate to a node-set". Can anyone tell me why and how to fix it?

sum(//Satellite/multidataset/file[contains(@name, '311multi')]/Data/ DriftAnalysis[contains(@name, '311')]/Metric[@name='Detail' and @type='Overlap']/Element[@metrictype='Overlap']/ OutputField[@name='Cleared']/@value)

And here is a snipit of the xml file that I'm zeoring in on.
 

Joe Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
1,229
Reaction score
0
Is this in an XSLT stylesheet? Assuming it is...

XSLT 1.0 draws a distinction between "result trees" and "node sets". Depending on how you're computing the results of that path and what you're doing with it (you didn't give us context), you may need to put the value through a conversion routine... which was not standardized at that time. The semi-standardized solution, if your processor supports the EXSLT extension library (most do, at this point) is to use the exslt:node-set function. There's a decent article on EXSLT at http://www.ibm.com/developerworks/library/x-exslt.html

(This distinction between trees and sets went away in XSLT 2.0. In a 2.0 processor nodes are all either in input-document trees or Temporary Trees, and the processing is the same for either kind of tree. So the other solution would be to find a processor which supports XSLT
2.0/XPath 2.0 and change your stylesheet's version declaration to specify that it wants to use these newer features.)
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Jack said:
But when I try to sum the returned values of the "value attribute" using the sum function like the example below I get the error "Expression must evaluate to a node-set". Can anyone tell me why and how to fix it?

sum(//Satellite/multidataset/file[contains(@name, '311multi')]/Data/ DriftAnalysis[contains(@name, '311')]/Metric[@name='Detail' and @type='Overlap']/Element[@metrictype='Overlap']/ OutputField[@name='Cleared']/@value)

How do you evaluate that expression? There are XPath APIs that only support evaluating expressions that returns a node-set, but not expressions that evaluate to a primitive value like a number, string or boolean value. Depending on the XPath API you use you might simply need to use a different method, for instance with .NET's XPathNavigator you can use http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.evaluate.aspx with any XPath expression while http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.select.aspx only allows expression evaluating to a node-sets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,244
Members
248,133
Latest member
DujonT

Latest Threads

Top