question

ChrisB avatar image
ChrisB asked ericnute edited

How can I make a case insensitive comparison in XPath?

Hi all,

 

I know I can do something ugly like this for the value I want to compare:

 

translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')

 

In a full example, that would be:

 

//people[ translate( firstName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz' ) = 'john doe' ]

 

Is there a better/cleaner way to do this?

 

Thanks!

chris

iTestxpath
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image
PaulD answered PaulD posted

Use the lower-case function:

 

//people[lower-case(firstName) = 'john doe']

1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ChrisB avatar image ChrisB commented ·

I just tried it and it works. Thanks for the help!

 

Does this mean that we're XPath 2.0 under the covers? I've been using only XPath 1.0 stuff up till now (thus my original post using translate).

 

Regards,

chris

0 Likes 0 ·
dclaar avatar image
dclaar Suspended answered dclaar Suspended posted
Probably not, unless XPath 2.0's lower-case() was slipped in, which--near as I can tell--it wasn't.
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image
dclaar Suspended answered dclaar Suspended posted

oops! I guess my test of to-lower was flawed!

 

I

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dclaar avatar image
dclaar Suspended answered dclaar Suspended posted

Sorry for the half-response, somehow I managed to submit the post via fat-fingering.

 

It would be nice to know exactly what functions are available!

1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image PaulD commented ·

Our xpath support is currently built on top of Jaxen 1.1.1.  You can find the documentation on all of the supported functions here.  Note that there are two groups of functions:  basic and extended.

 

In addition, iTest has also registered functions for max(), min(), and avg().  In addition, when performing mapping queries, iTest registers all queries as additional xpath functions.  That is because iTest's mapper queries are actually bona fide xpath expressions, and the information appearing the Queries view for a given step correspond to xpath functions that iTest registers for you automatically before issuing your mapper query to be evaluated via xpath.

 

 

0 Likes 0 ·
dclaar avatar image
dclaar Suspended answered dclaar Suspended posted
What exactly does evaluate(string) do? Does it do math? The documentation isn't really clear.
2 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

PaulD avatar image PaulD commented ·
The evaluate function can be used for evaluating another xpath expression within the context of this expression.  That can be very handy for dealing with a variety of tricky cases.
0 Likes 0 ·
dclaar avatar image dclaar PaulD commented ·
Can you post a simple example using evaluate?
0 Likes 0 ·
dclaar avatar image
dclaar Suspended answered dclaar Suspended posted

Wait, I'm confused. No, maybe I'm not. Then again... :smileytongue:

 

I had tried using a query function, and I couldn't get it to work, so I just figured that it wasn't supported, and went back to the full XPath. After seeing this post, I went back and tried it again, and it worked! So I guess I just didn't have it quite right the first time (I was also struggling with array variables at the time, so it was probably just too many, err, variables in the equation).

 

This is a really cool feature!

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.