webmasterbeta
New Member
hello everyone,
i am newbie to xquery. i am having this problem with my simple xquery. I am using eXist XML DB and using this query in PHP to retrieve result.
this is my xml database file.
<class>
<result>
<student>abc</student>
<grade>4</grade>
</result>
<result>
<student>xyz</student>
<grade>6</grade>
</result>
<result>
<student>pqr</student>
<grade>9</grade>
</result>
</class>
xQuery
1- $query = 'for $x in doc("test.xml")/class/result return if ($x/student="'.$studentName.'") then $x/grade';
2- $query = 'for $x in doc("test.xml")/class/result where $x/student=\".$studentName.\" return $x/grade;
Query 1 only works if $studentName="pqr" (i.e. the last element value in xml file). only works with the last elemenet.
i tried different combination including query 2 but nothing works. am i missing some basic thing here?
plz help
thank you
i am newbie to xquery. i am having this problem with my simple xquery. I am using eXist XML DB and using this query in PHP to retrieve result.
this is my xml database file.
<class>
<result>
<student>abc</student>
<grade>4</grade>
</result>
<result>
<student>xyz</student>
<grade>6</grade>
</result>
<result>
<student>pqr</student>
<grade>9</grade>
</result>
</class>
xQuery
1- $query = 'for $x in doc("test.xml")/class/result return if ($x/student="'.$studentName.'") then $x/grade';
2- $query = 'for $x in doc("test.xml")/class/result where $x/student=\".$studentName.\" return $x/grade;
Query 1 only works if $studentName="pqr" (i.e. the last element value in xml file). only works with the last elemenet.
i tried different combination including query 2 but nothing works. am i missing some basic thing here?
plz help
thank you