473,888 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(@n ame, 'bush'))
and before(@birthda te, '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 50590
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(@n ame, 'bush'))
and before(@birthda te, '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(translat e(@birthdate, '-', '')) <
number(translat e('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...@yaho o.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(@n ame, 'bush'))
and before(@birthda te, '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(translat e(@birthdate, '-', '')) <
number(translat e('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(@n ame, '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.comwr ote in message
news:11******** **************@ w3g2000hsg.goog legroups.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...@yaho o.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(@n ame, 'bush'))
and before(@birthda te, '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(translat e(@birthdate, '-', '')) <
number(transla te('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.c om.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(@n ame, '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.comwr ote in message

news:11******** **************@ w3g2000hsg.goog legroups.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...@yaho o.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(@n ame, 'bush'))
and before(@birthda te, '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(translat e(@birthdate, '-', '')) <
number(translat e('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
66880
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 Begin SELECT statement
2
2841
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 NAME/@id in the document tree and additionally a specific further conditions holds (@cid's shouldn't be the same). For that I would like to refer to the node selected in the "following" axes, but I do not know how to refer to this...
1
2296
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 tbl_Area_PropLend.ReportingMonth, tbl_Area_PropLend.Measure, tbl_Area_PropLend.Type HAVING (((tbl_Area_PropLend.ReportingMonth)=#8/1/2004#) AND ((tbl_Area_PropLend.Measure)=1) AND ((tbl_Area_PropLend.Type)=2));
1
1508
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 expression actually evaluates to what I expect (e.g. expected element names)? I can easily write a script which does the job, but would be happy to solve the problem with XSD, XSL or another 'standard' tool.
10
2702
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 I can't find the information I need (or maybe I can't understand it). So here's the thing: What I have is a range of integers, and I need those whose digits alternate between odd and even. Example: 123456789. For that purpose I have this...
13
2093
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
18246
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 while loop. Basically i need the condition in the while loop should contains "||". Is it possible? If not can anyone suggest me an alternative
3
3984
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 > 10 OR age < 5 AND name = 'myname'> I mean I need the table to return rows with the 3rd condition ( name='myname' ) and one of the other conditions ( age>10 ) or ( age<5 ) Thanks
1
4204
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"> <Style Color="Red" > <Car Name="R"/> </Style>
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.