Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variable attribute in Xquery/Xpath

Status
Not open for further replies.

modderman

Technical User
Sep 28, 2006
1
NZ
I have recently been working on a project for Uni using the eXist xmldb and of course xquery.



What I have been trying to do is search for a customer by the id attribute value.

For example
---------------------------
xquery version "1.0";

<ul>
{
let $x := data(doc("customer.xml")//customers/customerid[@id="02"])
return
<li>{data($x)}</li>
}
</ul>

--------------------------------

This returns a value as the whole thing is hard coded.

But I essentially have to have a user input data into an xhtml form which will pass the data into a variable.

I want to search for the customer with a variable from the input form.

However, when I use a variable, example below:

-------------------------------------------------


xquery version "1.0";

let $y := 02

<ul>
{
let $x := data(doc("customer.xml")//customers/customerid[@id=$y])
return
<li>{data($x)}</li>
}
</ul>


This outputs an error.

Note that this is only testing to see if I can input a variable the in path and there have been a few variations of this but none seems to output anything.


Could anybody help me?!

Any advice would be appreciated.

P.s please excuse by newbie syntax :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top