XPATH: expression question

Discussion in 'XML' started by Tjerk Wolterink, Mar 8, 2005.

  1. 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, Mar 8, 2005
    #1
    1. Advertising

  2. 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.
     
    Tjerk Wolterink, Mar 8, 2005
    #2
    1. Advertising


  3. > 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
     
    David Carlisle, Mar 8, 2005
    #3
  4. 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?
     
    Tjerk Wolterink, Mar 8, 2005
    #4
  5. In article <422dbb98$0$94717$>,
    Tjerk Wolterink <> 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
     
    Richard Tobin, Mar 8, 2005
    #5
  6. David Carlisle, Mar 8, 2005
    #6
  7. Tjerk Wolterink

    Peter Flynn Guest

    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` * &"
     
    Peter Flynn, Mar 11, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,983
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,423
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    532
  4. goog
    Replies:
    0
    Views:
    514
  5. GIMME
    Replies:
    3
    Views:
    11,978
    vforvikash
    Dec 29, 2008
Loading...

Share This Page