4
votes

I originally had written a simple XQuery script:

$mediaNodes := doc('/db/portfolio/media_data_101109.xml'),
$query := concat('$mediaNodes//media[contains(@product,"',$product,'")'

Basically, what it does is to first retrieve the xml file for the media records. Then I built up a query that search through all of the mediaNodes (elements of the xml file), and matching the @product attribute with what the user has supplied in the browser, and I've used contain, so no need to do exact matching.

Now I want to extend this a little bit, which is to ignore the case. So no matter what case the user has typed in browser, I will convert it to lower case, and I will also convert the node text to lower case too.

I searched online and found the function lower-case, and changed my code accordingly:

$query := concat('$mediaNodes//media[contains(lower-case(@product),"',lower-case($product),'")',

but this doesn't work, if I execute the query, there will be a heap overflow. The query that I got after running with product=wborc looks like:

$mediaNodes//media[contains(lower-case(@product),"wborc")]

Could anybody help me a little bit? I am not sure whether I am making syntactic mistake or logic one. Thanks in advance.

1
Your question is very unclear: 1. What is the XML document you are querying (the minimal possible, please). 2. What exactly is the desired result for this XML document? 3. What is the meaning of the desired result? - Dimitre Novatchev
Good question, +1. See my answer for a complete solution. :) - Dimitre Novatchev
there were some minor adjustments -- see my latest updated answer. - Dimitre Novatchev
It looks like you are building a string that suppose to be an XQuery expression, maybe for a second step query or a not standar dynamic evaluation. Both kind of solutions seems to be a bad design choice, mostly because this is a so simple query... - user357812
@Alejandro: exactly, this is for an XQuery expression on eXist db, and actually it always makes my query webpage crash and heap overflow. Have no idea why so far. - Kevin

1 Answers

3
votes

Use:

concat('$vmediaNodes//media
        [contains(lower-case(@product),','lower-case("',$vProduct,'"))]')