By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

XPath: Multiple conditions (contains, dates, node-set)

P: n/a
Hi all,

I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'), and so on.

This is the thought:

//person[contains(@name, 'george') and not(contains(@name, 'bush'))
and before(@birthdate, '1980-01-01')]

How can I accomplish this? there are problems if the results of a
condition is a node-set or not I suppose. Every condition is generated
and added to the expression, the problem is that it MUST be one
expression, since I need to read it and load my controls with the
condition.

My UI looks like:
DropDown with the attributes
DropDown with some functions (contains, etc)
Textboxes for the strings/dates to compare the attributes with

What I am trying to accomplish is "refine your search" functionality,
or in other words "Live filters" where if the XML is changed, the
xpath is run and the view is updated.

Any ideas on how to do this using XPath/XQuery and .NET?

Thanks!
/ jorge

Aug 2 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
jo***************@gmail.com wrote:
I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'), and so on.

This is the thought:

//person[contains(@name, 'george') and not(contains(@name, 'bush'))
and before(@birthdate, '1980-01-01')]
There is no before function in XPath 1.0. There is <, <=, >, >=
comparison in XPath 1.0 but only for numbers so you can compare dates in
the form yyyy-mm-dd using
number(translate(@birthdate, '-', '')) <
number(translate('1980-01-01'), '-', '')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 3 '07 #2

P: n/a
Yes, XPath1 does not have support for dates, which means having to
compare the parts of a date as integers. the "before" example was just
to make the point. But thanks for the reply.

The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.

/ jorge

On 3 Aug, 12:19, Martin Honnen <mahotr...@yahoo.dewrote:
jorgedelgadolo...@gmail.com wrote:
I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'), and so on.
This is the thought:
//person[contains(@name, 'george') and not(contains(@name, 'bush'))
and before(@birthdate, '1980-01-01')]

There is no before function in XPath 1.0. There is <, <=, >, >=
comparison in XPath 1.0 but only for numbers so you can compare dates in
the form yyyy-mm-dd using
number(translate(@birthdate, '-', '')) <
number(translate('1980-01-01'), '-', '')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Aug 4 '07 #3

P: n/a
jo***************@gmail.com wrote:
The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.
I am not sure what you are asking about. It is certainly possible to use
e.g.
element1[element2 and @attr1 = 'value 1']

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 4 '07 #4

P: n/a
The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.
Actually, there is *no* problem with this.

The XPath expression:

//person[contains(@name, 'george') and not(contains(@name, 'bush'))

will select all "person" elements whose "name" attribute contains the string
"george" and does not contain the string "bush".

Where do you see a problem?
Cheers,
Dimitre Novatchev

P.S. I recommend using the XPath Visuaizer for learning XPath the fun way --
in case there is any doubt how an XPath expression will be evaluated, just
use the XPath Visualizer to see.
<jo***************@gmail.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
Yes, XPath1 does not have support for dates, which means having to
compare the parts of a date as integers. the "before" example was just
to make the point. But thanks for the reply.

The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.

/ jorge

On 3 Aug, 12:19, Martin Honnen <mahotr...@yahoo.dewrote:
>jorgedelgadolo...@gmail.com wrote:
I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'), and so on.
This is the thought:
//person[contains(@name, 'george') and not(contains(@name, 'bush'))
and before(@birthdate, '1980-01-01')]

There is no before function in XPath 1.0. There is <, <=, >, >=
comparison in XPath 1.0 but only for numbers so you can compare dates in
the form yyyy-mm-dd using
number(translate(@birthdate, '-', '')) <
number(translate('1980-01-01'), '-', '')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Aug 4 '07 #5

P: n/a
Well, so it seems that it works, I skipped the dates for now. Very
strange, I wasnt getting the correct results on the expression i had
created. but a few tweaks and now it works fine. I wonder what it was,
the first condition returned a node-set and the next one didnt operate
on that node-set. oh well. it works now..

thanks Dimitre
/ jorge

On 4 Aug, 15:19, "Dimitre Novatchev" <dimit...@tpg.com.auwrote:
The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.

Actually, there is *no* problem with this.

The XPath expression:

//person[contains(@name, 'george') and not(contains(@name, 'bush'))

will select all "person" elements whose "name" attribute contains the string
"george" and does not contain the string "bush".

Where do you see a problem?

Cheers,
Dimitre Novatchev

P.S. I recommend using the XPath Visuaizer for learning XPath the fun way --
in case there is any doubt how an XPath expression will be evaluated, just
use the XPath Visualizer to see.

<jorgedelgadolo...@gmail.comwrote in message

news:11**********************@w3g2000hsg.googlegro ups.com...
Yes, XPath1 does not have support for dates, which means having to
compare the parts of a date as integers. the "before" example was just
to make the point. But thanks for the reply.
The actual problem has to do more with the " and " operator between
all the conditions, if the first one returns a node-set and so on.
/ jorge
On 3 Aug, 12:19, Martin Honnen <mahotr...@yahoo.dewrote:
jorgedelgadolo...@gmail.com wrote:
I am using the xpathnavigator evaluate function on .net (xpath 1
right?). Now I need to expand the code to do multiple contains,
compare dates (such as 'before', 'between' and 'after'), and so on.
This is the thought:
//person[contains(@name, 'george') and not(contains(@name, 'bush'))
and before(@birthdate, '1980-01-01')]
There is no before function in XPath 1.0. There is <, <=, >, >=
comparison in XPath 1.0 but only for numbers so you can compare dates in
the form yyyy-mm-dd using
number(translate(@birthdate, '-', '')) <
number(translate('1980-01-01'), '-', '')
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Aug 5 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.