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 like the example below I get the error "Expression must evaluate to a node-set error". 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.

.
.
.
<Metric name="Detail" type="Overlap">
  <Element name="PFMR Inactive" metrictype="Overlap" category="MAIN" aname="Detail|PFMR Inactive" metricstatistic="UniqueValueOverlap" label="PFMR Inactive">
    <OutputField name="Rome - 20101201" value="2"/>
    <OutputField name="Rome - 20101229" value="2"/>
    <OutputField name="Difference" value="0"/>
    <OutputField name="Cleared" value="0"/>
    <OutputField name="Remaining" value="2"/>
    <OutputField name="New" value="0"/>
  </Element>
  <Element name="FUND-CODE Invalid" metrictype="Overlap" category="MAIN" aname="Detail|FUND-CODE Invalid" metricstatistic="UniqueValueOverlap" label="FUND-CODE Invalid">
    <OutputField name="Rome - 20101201" value="0"/>
    <OutputField name="Rome - 20101229" value="0"/>
    <OutputField name="Difference" value="0"/>
    <OutputField name="Cleared" value="0"/>
    <OutputField name="Remaining" value="0"/>
    <OutputField name="New" value="0"/>
  </Element>
    .
    .
    .
</Metric>
.
.
.

I used the below xml as input

<Metric name="Detail" type="Overlap">
  <Element name="PFMR Inactive" metrictype="Overlap" category="MAIN" aname="Detail|PFMR Inactive" metricstatistic="UniqueValueOverlap" label="PFMR Inactive">
    <OutputField name="Rome - 20101201" value="2"/>
    <OutputField name="Rome - 20101229" value="2"/>
    <OutputField name="Difference" value="0"/>
    <OutputField name="Cleared" value="1"/>
    <OutputField name="Remaining" value="2"/>
    <OutputField name="New" value="0"/>
  </Element>
  <Element name="FUND-CODE Invalid" metrictype="Overlap" category="MAIN" aname="Detail|FUND-CODE Invalid" metricstatistic="UniqueValueOverlap" label="FUND-CODE Invalid">
    <OutputField name="Rome - 20101201" value="0"/>
    <OutputField name="Rome - 20101229" value="0"/>
    <OutputField name="Difference" value="0"/>
    <OutputField name="Cleared" value="0"/>
    <OutputField name="Remaining" value="0"/>
    <OutputField name="New" value="0"/>
  </Element>
</Metric>

used the below template

<xsl:template match="/">

<xsl:value-of select="sum(Metric[@name='Detail' and  @type='Overlap']/Element[@metrictype='Overlap']/OutputField[@name='Cleared']/@value)"/>

</xsl:template>

and got an output as 1. The output is correct. If you still face the error, then please post the xslt code you use and the relevant input xml.

This article has been dead for over six months. Start a new discussion instead.