Hi, I'm new to xpath. I have some question I dont know how to do it.. I've googled about it and i dont see any solution.


I wanted to do a math calculation.(this i know how to do) but then i wanted it to display it out using my xpath query..
can someone be kind enough to show me some simple calculation which it will come out with the number??

exp: //Studentsum(Subjects/Marks)>100 - this is just to show out the which student have the marks more than 100. But what i want is i wanted to display out the total Marks ( number ) Any idea??

2nd Question:

I'm just wondering.. can xPath put the numbers or string... into a variable?? ^^ just wondering..

Thanks for anyone who helping me.. cause I'm realy new to xpath..

Or do you all have any link which can teach me how to display out the number / putting the number into a variable? ^^

Best Regards,

Member Avatar


(1) XPath has the sum() function; I'm not sure exactly what you're looking for, but if you want to display the total <marks>, you would write

<xsl:value-of select="sum(//marks)"/>

(2) XPath can be used to *assign* a variable, but it's up to the language using XPath (XSLT, VB, Java, etc.) to create the variable.

<xsl:variable name="totalMarks" select="sum(//marks)"/>

The variable $totalMarks now contains a number.

<xsl:value-of select="$totalMarks"/>

I'm really appreciate for your reply.. thanks a lot..

But what i'm handling now isn't related to xsl
I'm using a program which will get xpath queries..

xml data :

<FirstName>Yien Yien</FirstName>

queries : /Students/Student[count(Subjects/Subject)=0]
result : this will search student that register but did not take any subject

I didnt use any xsl on this.. i wanted to make a queries that can sum up the marks for that student.. am i possible get the sum for the marks by using only xpath queries??

Is it possible? ^^

Best Regards,

Member Avatar


The XPath will be the same, regardless of whether you're using XSLT or a programming language; just remove the expression from the "select" statements.



Will sum the marks for all Students, or if you're looping through all Students


(assuming that the XPath is operating from within a loop of Students).