473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
5 50532
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: M Wells | last post by:
Hi All, Just wondering if anyone can tell me if you can test for multiple conditions as part of an "IF" statement in T-SQL in SQL Server 2000? ie something like: IF @merr = 1 or @merr=2...
2
by: Ginu | last post by:
Hi, the task is to identify semantically identical elements where some additional attributes do not match. The XSL-transformation should find a node NAME which @id attribute matches to another...
1
by: Work.Smarter.1 | last post by:
How do i subtract the first value from the second value without multiple queries? (query example below) SELECT Sum(tbl_Area_PropLend.Amount) AS Default_FinCharge FROM tbl_Area_PropLend GROUP BY...
1
by: ssvendsen | last post by:
Hi, In my XML dialect I got elements on the form of XPath expressions, which refer to nodesets located in other fragments in the same document. Is there a way to validate that the XPath...
10
by: greedo | last post by:
Hi, first of all, please bear with me, I don't really know a great deal about php programming, as will be painfully obvious from the code snippet I'm gonna post. But I need this problem solved, and...
13
by: TheLostLeaf | last post by:
Hi, Does anyone know if these 2 code segments would operate the same way. for instance if the first condition fails does it bother to check the second? if (MyList.Count 0 && CheckDate) {
3
by: kavithapotnuru | last post by:
Hi All, Can anyone help me how to give multiple conditions in a while loop in perl. For example i have a while loop for which the value of a variable is A or B it should not enter in to the...
3
by: bnashenas1984 | last post by:
Hi everyone I'v been looking in google but haven't got any answer for my question yet. Actualy I have a search page which works with mysql. my question is: SELECT * FROM usertable WHERE age >...
1
by: ajayvaram | last post by:
<?xml version="1.0" encoding="utf-8"?> <CategoryList> <Category ID="01" Title="One"> </Category> <Category ID="03" Title="Three"> </Category> <Category ID="04" Title="Four"> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.