473,554 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding "last node with value less than" with XPath

Hello,

I'm considering using XML to represent a stream of location
information, and XPath to do queries against it. I've got most of it
figured out (at least on paper), but I can't figure out how to create
an XPath statement asking for the "last node with a value less than" a
given value.

I need this to be able to ask "Where was Scott at 11:00 yesterday",
which should find the last sighting of Scott before or at 11:00
yesterday. For example, in this (simplified) data:

<!-- Thousands of previous sightings -->
<saw> <who> Scott </who><where> Office </where><when> 10:57 </when></saw>
<saw> <who> Tom </who><where> Office </where><when> 10:57 </when></saw>
<saw> <who> Scott </who><where> Hallway </where><when> 10:58 </when></saw>
<saw> <who> Tom </who><where> Breakroom </where><when> 10:59 </when></saw>
<saw> <who> Sally </who><where> Rooftop </where><when> 11:00 </when></saw>
<saw> <who> Scott </who><where> Dungeon </where><when> 11:01 </when></saw>
<!-- Thousands of later sightings -->

I want:

<saw> <who> Scott </who><where> Hallway </where><when> 10:58 </when></saw>

Is it possible to express this in XPath? And if so, what's the best way?

Thanks!

----ScottG.
Aug 12 '05 #1
7 2149
Hi,
Tempore 22:39:07, die Friday 12 August 2005 AD, hinc in foro {comp.text.xml} scripsit Scott W Gifford <gi*****@umich. edu>:
Hello,

I'm considering using XML to represent a stream of location
information, and XPath to do queries against it. I've got most of it
figured out (at least on paper), but I can't figure out how to create
an XPath statement asking for the "last node with a value less than" a
given value.

I need this to be able to ask "Where was Scott at 11:00 yesterday",
which should find the last sighting of Scott before or at 11:00
yesterday.


Without providing any exclusion on the matter of performance, I can tell you that this would work:

<xsl:variable name="seenYeste rday"
select=".//saw"/>
<xsl:variable name="ScottSigh ted"
select="$seenYe sterday[normalize-space(who)='Sco tt']"/>
<xsl:value-of
select="$ScottS ighted[translate(when, ': ','') &lt;= 1100][last()]"/>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Η αλήθεια και το λάδι πάντα βγαίνου από πάνω»
Aug 12 '05 #2
"Joris Gillis" <ro**@pandora.b e> writes:
Tempore 22:39:07, die Friday 12 August 2005 AD, hinc in foro {comp.text.xml} scripsit Scott W Gifford <gi*****@umich. edu>:
I'm considering using XML to represent a stream of location
information, and XPath to do queries against it. I've got most of it
figured out (at least on paper), but I can't figure out how to create
an XPath statement asking for the "last node with a value less than" a
given value.

[...]
Without providing any exclusion on the matter of performance, I can
tell you that this would work:

<xsl:variable name="seenYeste rday"
select=".//saw"/>
<xsl:variable name="ScottSigh ted"
select="$seenYe sterday[normalize-space(who)='Sco tt']"/>
<xsl:value-of
select="$ScottS ighted[translate(when, ': ','') &lt;= 1100][last()]"/>


Hi Joris,

Is it possible to do this with pure XPath? I'm doing queries in a
client/server environment (similar to Xindice and YFilter, which I'll
probably use as backends), and I wasn't planning on using XSLT.

If I simplify my data by changing the time format from "11:00" to
"1100", this looks right, but doesn't work with Xindice:

//saw[who=" Scott " and when <= 1100][last()]

However the below query works correctly, so it's getting the right
data, just not selecting the last node:

//saw[who=" Scott " and when <= 1100][last()]

Thanks for any advice,

----ScottG.
Aug 12 '05 #3
Tempore 23:53:00, die Friday 12 August 2005 AD, hinc in foro {comp.text.xml} scripsit Scott W Gifford <gi*****@umich. edu>:
If I simplify my data by changing the time format from "11:00" to
"1100", this looks right, but doesn't work with Xindice:

//saw[who=" Scott " and when <= 1100][last()]

However the below query works correctly, so it's getting the right
data, just not selecting the last node:

//saw[who=" Scott " and when <= 1100][last()]


I don't see any diference between these 2 queries. They both give the correct result with my XSLT processor (ALtovaXSLT).

Do remember that '//' should be replaced with more specific location steps as soon as you've made up your mind about the XML structure.

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Aug 13 '05 #4
In article <qs************ *@arkanoid.gpcc .itd.umich.edu> ,
Scott W Gifford <gi*****@umich. edu> wrote:
If I simplify my data by changing the time format from "11:00" to
"1100", this looks right, but doesn't work with Xindice:

//saw[who=" Scott " and when <= 1100][last()]

However the below query works correctly, so it's getting the right
data, just not selecting the last node:

//saw[who=" Scott " and when <= 1100][last()]


Um, those two queries are identical...

But it doesn't mean "the last <saw> in the document matching the the
condition", it means "the <saw>s matching the condition that are the
last such child of their parent". For the former, you need

(//saw[who=" Scott " and when <= 1100])[last()]

(i.e. put parentheses around the art that selects the nodes).

-- Richard
Aug 14 '05 #5
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <qs************ *@arkanoid.gpcc .itd.umich.edu> ,
Scott W Gifford <gi*****@umich. edu> wrote:
If I simplify my data by changing the time format from "11:00" to
"1100", this looks right, but doesn't work with Xindice:

//saw[who=" Scott " and when <= 1100][last()]

However the below query works correctly, so it's getting the right
data, just not selecting the last node:

//saw[who=" Scott " and when <= 1100][last()]
Um, those two queries are identical...


Err..Yeah. Cut-n-paste error. I meant:

//saw[who=" Scott " and when <= 1100][last()]
//saw[who=" Scott " and when <= 1100][2]

in the case when there are 2 entries.
But it doesn't mean "the last <saw> in the document matching the the
condition", it means "the <saw>s matching the condition that are the
last such child of their parent". For the former, you need

(//saw[who=" Scott " and when <= 1100])[last()]

(i.e. put parentheses around the art that selects the nodes).


Thanks for the hint, but neither of these return any results for me:

(//saw[who=" Scott " and when <= 1100])[last()]
(//saw[who=" Scott " and when <= 1100])[2]

Am I running into bugs in Xindice here, or is this query still not
quite right?

Thanks!

----ScottG.
Aug 15 '05 #6
In article <qs************ *@arkanoid.gpcc .itd.umich.edu> ,
Scott W Gifford <gi*****@umich. edu> wrote:
Am I running into bugs in Xindice here, or is this query still not
quite right?


Try it with a different processor (e.g. embed it in a stylesheet and
try Saxon or Xalan).

-- Richard
Aug 15 '05 #7
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <qs************ *@arkanoid.gpcc .itd.umich.edu> ,
Scott W Gifford <gi*****@umich. edu> wrote:
Am I running into bugs in Xindice here, or is this query still not
quite right?


Try it with a different processor (e.g. embed it in a stylesheet and
try Saxon or Xalan).


Ah, thanks, it works with Saxon at least!

I'm going to end up with quite a large database, however, and making
one giant XML document with all the information, then asking Saxon to
scan this document for each query, will probably not scale well. Can
anybody recommend a good XML database that supports a reasonably large
subset of XPath and is efficient enough to handle many thousands of
small documents?

Thanks!

----ScottG.
Aug 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
27868
by: M Bourgon | last post by:
I'm trying to figure out how to find the last whitespace character in a varchar string. To complicate things, it's not just spaces that I'm looking for, but certain ascii characters (otherwise, obviously, just use LEN). My initial thought was to REVERSE it, find the location (using CHARINDEX) looking for each of those characters (so,...
32
4107
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:"...
2
2557
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or place holders, as two examples below: Example - File type 1
0
7535
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...
0
7812
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. ...
1
7574
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...
0
6161
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5442
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...
0
3579
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3561
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2026
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
0
850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.