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

XPATH: expression question

Given an node with path a/b[@id=1]

how do i get the next three following sibling nodes?

example document

<a>
<b id="1"/>
<b/>
<b/>
<b/>
</a>
ok you could say: a/b[not(@id)], but that are only three in this example doc.
but i dont know the exact path,
the only thin is know is that . or node() is some b node.

i use these xpath expression in an xsl tranformation where i want to
create a table with images.

look at this:

<table>
<xsl:for-each select="b[(position() mod 3)=1]">
<tr>
<td>
<xsl:call-template name="sometempl">
<xsl:with-param name="param" select="."/>
</xsl:call-template>
</td>
<td>
<xsl:if test="following-sibling::node()[position()=1]">
<xsl:call-template name="sometempl">
<xsl:with-param name="param" select="following-sibling::node()[position()=1]/>
</xsl:call-template>
</xsl:if>
</td>
<td>
<xsl:if test="following-sibling::node()[position()=2]">
<xsl:call-template name="sometempl">
<xsl:with-param name="param" select="following-sibling::node()[position()=2]/>
</xsl:call-template>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>

but this does not work
hope you know what i mean.
Jul 20 '05 #1
6 1270
Tjerk Wolterink wrote:
Given an node with path a/b[@id=1]
[cut]


ok,
what does following-sibling exactly mean??
I am dutch and i cannot find the word Sibling in my english dictionairy.
Jul 20 '05 #2
I am dutch and i cannot find the word Sibling in my english dictionairy.


sibling means children of your parent, ie it means brother-or-sister,
except that XML nodes have several properties but gender is not one of
them so "brother-or-sister" doesn't sound quite right.

following-sibling means all nodes that are later in document order than
the current node, following-sibling::*[position()&lt;4] finds the next
three element nodes that are siblings.

David
Jul 20 '05 #3
David Carlisle wrote:
I am dutch and i cannot find the word Sibling in my english dictionairy.

sibling means children of your parent, ie it means brother-or-sister,
except that XML nodes have several properties but gender is not one of
them so "brother-or-sister" doesn't sound quite right.

following-sibling means all nodes that are later in document order than
the current node, following-sibling::*[position()&lt;4] finds the next
three element nodes that are siblings.

David


ok then there is something wrong with my xsl-parser.

with this xsl:

<xsl:for-each select="./xc:item[(position() mod $cols)=1]">
<row>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::node()[position() &lt; $cols+1]"/>
</row>
</xsl:for-each>

....
<xsl:template match="xc:item">
<col>X</col>
</xsl:template>

But know when $cols=3 i get this:

<row>
<col>X</col>
<col>X</col>
</row>
<row>
<col>X</col>
<col>X</col>
</row>
<row>
<col>X</col>
<col>X</col>
</row>
but there should be 3 cols?? Or am i wrong?
Jul 20 '05 #4
In article <42***********************@news.wanadoo.nl>,
Tjerk Wolterink <tj***@wolterinkwebdesign.com> wrote:
But know when $cols=3 i get this: <row>
<col>X</col>
<col>X</col>
</row> but there should be 3 cols?? Or am i wrong?


Bear in mind that node() will match the whitespace text nodes between
elements as well as the elements themselves. If you want the
following *element* siblings, use * instead of node().

-- Richard
Jul 20 '05 #5
Or am i wrong?


yes see Richard's reply (and note I did use * in the example that you quoted:-)
This is a faq, the xsl-list faq has lots on this, eg

http://www.dpawson.co.uk/xsl/sect2/N6099.html#d7586e70

David
Jul 20 '05 #6
Tjerk Wolterink wrote:
Given an node with path a/b[@id=1]

how do i get the next three following sibling nodes?

example document

<a>
<b id="1"/>
<b/>
<b/>
<b/>
</a>


a/b[@id="1"]/following-sibling::b

///Peter
--
sudo sh -c "cd /; /bin/rm -rf `which killall kill ps shutdown` * &"

Jul 20 '05 #7

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

Similar topics

0
by: Anna | last post by:
Hi all. I hav eproblems constructing one XPath expression. Here is what I want to do: I want to choose all area tags that belong to a certain image map, having src of the image map. I don't want...
2
by: GIMME | last post by:
For starters .... If : //input is the xpath syntax to see if an element with an attribute named start_date exists ... Then what is the xpath syntax to return elements having
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
2
by: gimme_this_gimme_that | last post by:
What xpath expression would return the category-item having uid sps002 ? <category-list> <category> <uid>GRIDS_MAIN_CATEGORY_UID</uid> <uid-type>Categories</uid-type> <category-item-list>...
7
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange";...
2
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the...
7
by: Gary McGill | last post by:
Suppose I have an xml file that looks like this: <example> <foo id="1"> <bar id="a1"/> <bar id="b1"/> ... </foo> <foo id="2"> <bar id="a2"/>
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
2
by: Paul | last post by:
I'd like to write an XPath expression that gets all nodes with a given local-name, say 'Customer', within a given namespace. From a prior response I got the following to get nodes with a specific...
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: 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
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,...
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.