XPATH: expression question

Tjerk Wolterink

Usenet Archive
Joined
Sep 18, 2004
Messages
218
Reaction score
0
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.
 

Tjerk Wolterink

Usenet Archive
Joined
Sep 18, 2004
Messages
218
Reaction score
0
Tjerk said:
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.
 

David Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
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
 

Tjerk Wolterink

Usenet Archive
Joined
Sep 18, 2004
Messages
218
Reaction score
0
David said:
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?
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Tjerk Wolterink said:
But know when $cols=3 i get this:

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
 

Peter Flynn

Usenet Archive
Joined
Jan 2, 2000
Messages
1,813
Reaction score
0
Tjerk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top