Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPATH: expression question

Reply
Thread Tools

XPATH: expression question

 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      03-08-2005
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.
 
Reply With Quote
 
 
 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      03-08-2005
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.
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      03-08-2005

> 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
 
Reply With Quote
 
Tjerk Wolterink
Guest
Posts: n/a
 
      03-08-2005
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?
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      03-08-2005
In article <422dbb98$0$94717$(E-Mail Removed)>,
Tjerk Wolterink <(E-Mail Removed)> 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
 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      03-08-2005

> 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
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      03-11-2005
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` * &"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments