473,387 Members | 1,876 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,387 software developers and data experts.

Parallel data traversal

Hi,

I have some xml data looking like this
<root>
<items1>
<i1>..</i1>
<i1>..</i1>
</items1>
<items2>
<i2>..</i2>
<i2>..</i2>
</items2>
</root>

If my context node is the k-th node in items1 is to possible to create
XPath that finds a k-th node in items2? Something like "../../
items2[position() = position(.)]" - which does not work because "." is
bound to some "i2" node inside the square brackets.

Some motivation: we use a "repeater" component that traverses child
nodes of one node. The current node in the repeater is the context
node. The user then uses xpaths relative to the current node to get
the data. And I need some hack to be able to reference nodes at the
same position but inside a different node.

Obviously the most natural solution is to do some data preprocessing
to "zip" items1 and items2 together or modify our repeater to be able
to have multiple context nodes. But isn't there any pure xpath way to
do this?

Thanks

Sep 10 '07 #1
2 1712

Vojta <dr****@seznam.czwrote in
<11**********************@r34g2000hsd.googlegroups .com>:
<root>
<items1>
<i1>..</i1>
<i1>..</i1>
</items1>
<items2>
<i2>..</i2>
<i2>..</i2>
</items2>
</root>

If my context node is the k-th node in items1 is to
possible to create XPath that finds a k-th node in items2?
Something like "../../ items2[position() = position(.)]" -
which does not work because "." is bound to some "i2" node
inside the square brackets.

Obviously the most natural solution is to do some data
preprocessing to "zip" items1 and items2 together or
modify our repeater to be able to have multiple context
nodes.
That is the most natural solution indeed. And it's a trivial
transformation, too.
But isn't there any pure xpath way to do this?
Short answer: no, there isn't any pure XPath way of doing
that. You need either variables (that is, you have to
generate the XPath expression on the fly, it cannot be
static), or XPath extensions (XSLT defines the current()
function which returns the current node; but the notion of
the current node is defined by XSLT spec as well, and isn't
by itself meaningful outside of XSLT context).

--
This chickenus crossed the roadus while yodelingus.
Sep 10 '07 #2
Vojta wrote:
Hi,

I have some xml data looking like this
<root>
<items1>
<i1>..</i1>
<i1>..</i1>
</items1>
<items2>
<i2>..</i2>
<i2>..</i2>
</items2>
</root>

If my context node is the k-th node in items1 is to possible to create
XPath that finds a k-th node in items2? Something like "../../
items2[position() = position(.)]" - which does not work because "." is
bound to some "i2" node inside the square brackets.

Some motivation: we use a "repeater" component that traverses child
nodes of one node. The current node in the repeater is the context
node. The user then uses xpaths relative to the current node to get
the data. And I need some hack to be able to reference nodes at the
same position but inside a different node.

Obviously the most natural solution is to do some data preprocessing
to "zip" items1 and items2 together or modify our repeater to be able
to have multiple context nodes. But isn't there any pure xpath way to
do this?

Thanks
not pure xpath1 you need xslt1 or a similar host language that can bind
xpath variables.

however in xpath2 you can express this, for example

for $p in 1+count(preceding-sibling::i1) return
.../preceding-sibling::items2/i2[$p]

David
--
http://dpcarlisle.blogspot.com
Sep 10 '07 #3

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

Similar topics

0
by: Yuancai \(Charlie\) Ye | last post by:
Hi, All: I am happy to annouce that we have formally released our latest SocketPro version 4 at www.udaparts.com, an advanced remoting framework written from batching/queue, asynchrony and...
1
by: guy001 | last post by:
Hi, I'm trying to traverse the DOM in a bit of a non-traditional manner and am struggling to get my head around it. Just say i have some elements like so: A |-B |-C | |-D |
11
by: Isaac T Alston | last post by:
Basically, I'm thinking about building a robot which can be controlled by programs which I write, I'm going to interface to the robot through the parallel port (like in this tutorial here:...
11
by: lovecreatesbeauty | last post by:
For example, line L1 and line L2 are two lines in two-dimensional space, the start-points and end-points can be described with following the `point_t' type. The start-points and end-points are:...
6
by: GrispernMix | last post by:
//ques and and level order traversal file name: lab6_build_leaf_up.cpp Instructions:
2
by: hari | last post by:
Hi all, I need to automate printer command testing, prinetr supports parallel/ serial/USB.How can i send the commands from python to printer. I have got pyparallel, as am new to python, no...
4
by: Soren | last post by:
Hi, I want to control some motors using the parallel port.. however, my laptop does not have any parallel ports (very few do). What I do have is a USB->Parallel converter... I thought about...
3
by: John | last post by:
I have a program that needs to run on a regular basis that looks at a queue table in my database. If there are items in the queue database I need to grab the data from the database and pass it to...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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.