xquery and node values, and like

J

Jeff Kish

Hi.

I see it appears that xquery is case senstitive for looking for particular attribute values etc.
Is there a standard way around this? Say I want to see all nodes with an attribute valued
"copyright" or some such?


Finally, is there a "like" function similar to sql? I perused the docs and did not see anything, but
was wondering if I missed it, or if there is a way around it? Maybe I need to write a user function?

Thanks
Jeff
 
M

Martin Honnen

Jeff Kish wrote:

I see it appears that xquery is case senstitive for looking for particular attribute values etc.
Is there a standard way around this? Say I want to see all nodes with an attribute valued
"copyright" or some such?

In XPath you could do
//*[translate(@attribute, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz') = 'copyright']
and as XQuery has the same functions that should work there too.
And you have regular expression matching in XPath 2.0 respectively
XQuery 1.0.
Also there are easier ways to do that in XPath 2.0 and XQuery 1.0, there
is a function
lower-case
see
http://www.w3.org/TR/xquery-operators/#func-lower-case
Finally, is there a "like" function similar to sql? I perused the docs and did not see anything, but
was wondering if I missed it, or if there is a way around it?

There are functions using regular expressions
http://www.w3.org/TR/xquery-operators/#string.match
 
J

Jeff Kish

Jeff Kish wrote:

I see it appears that xquery is case senstitive for looking for particular attribute values etc.
Is there a standard way around this? Say I want to see all nodes with an attribute valued
"copyright" or some such?

In XPath you could do
//*[translate(@attribute, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz') = 'copyright']
and as XQuery has the same functions that should work there too.
And you have regular expression matching in XPath 2.0 respectively
XQuery 1.0.
Also there are easier ways to do that in XPath 2.0 and XQuery 1.0, there
is a function
lower-case
see
http://www.w3.org/TR/xquery-operators/#func-lower-case
Finally, is there a "like" function similar to sql? I perused the docs and did not see anything, but
was wondering if I missed it, or if there is a way around it?

There are functions using regular expressions
http://www.w3.org/TR/xquery-operators/#string.match
This appears to be a huge help. Thanks.
Jeff Kish
 
J

Jeff Kish

Jeff Kish wrote:

I see it appears that xquery is case senstitive for looking for particular attribute values etc.
Is there a standard way around this? Say I want to see all nodes with an attribute valued
"copyright" or some such?

In XPath you could do
//*[translate(@attribute, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz') = 'copyright']
and as XQuery has the same functions that should work there too.
And you have regular expression matching in XPath 2.0 respectively
XQuery 1.0.
Also there are easier ways to do that in XPath 2.0 and XQuery 1.0, there
is a function
lower-case
see
http://www.w3.org/TR/xquery-operators/#func-lower-case
Finally, is there a "like" function similar to sql? I perused the docs and did not see anything, but
was wondering if I missed it, or if there is a way around it?

There are functions using regular expressions
http://www.w3.org/TR/xquery-operators/#string.match
I seem to be having difficulty making this lower-case work...
For example I want to see if any attribute equals a value, so I tried this (which was worthless
except to show it was not right):

for $b in document("labrep.xml")//presentation
for $a in $b//*
where $a[fn:lower-case(@*)="pageHeader"]
return
<theElement> {name($a)}
<theAttributes>
{ $a/@*, name($a)}
</theAttributes> </theElement>
 
D

David Carlisle

you can use lower-case() you don't need fn:lower-case()

lower-case expects a string but you have done fn:lower-case(@*) so you
have passed a sequence of nodes (from all the attributes) in XPath1
coersion to string would just take the first node and junk the rest, in
Xquery it's an error if you have more than one attribute.

Do you really not know the attribute name that may
or may not have the pageHeader value? also the lowercase of anything is
not likely to be equal to "pageHeader" as H is not lower case.
You want
$a[(for $at in @* return lower-case($at)) ="pageheader"]

or just use =

$a[ @* ="pageHeader"]

and set the default collation to be a case insensitive comparison (if
your system has such a collation available)

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top