XPath: How to select all nodes which don't have children`

Discussion in 'XML' started by Hannes Heckner, Oct 13, 2003.

  1. I have:

    <data>
    <item>
    <object>bla</object>
    </item>
    <item>
    </item>
    <item>
    <object>blabla</object>
    </item>

    now I want to build 2 lists with <xsl:for-each>
    the first list should only display all items which have children
    the second list should only dipslay all items which don't have children-

    The first one I got myslef with:
    <xsl:for-each select="/data/item/object/.."> ...

    But the second list I cannot create
    I thought about
    <xsl:for-each select="/data/item/not(object)/..">

    but it does not compile

    Any help?

    Thanks
    Hannes
    Hannes Heckner, Oct 13, 2003
    #1
    1. Advertising

  2. Hannes Heckner wrote:

    > I have:
    >
    > <data>
    > <item>
    > <object>bla</object>
    > </item>
    > <item>
    > </item>
    > <item>
    > <object>blabla</object>
    > </item>
    >
    > now I want to build 2 lists with <xsl:for-each>
    > the first list should only display all items which have children
    > the second list should only dipslay all items which don't have children-
    >
    > The first one I got myslef with:
    > <xsl:for-each select="/data/item/object/.."> ...


    I think you want
    /data/item[object]
    >
    > But the second list I cannot create
    > I thought about
    > <xsl:for-each select="/data/item/not(object)/..">


    That should be
    /data/item[not(node())]
    if you want the empty <item> elements. However some implementations
    count white space as text nodes so make sure you write
    <item></item>
    to markup empty elements or use
    /data/item[not(*)]
    to select the <item> elements that do not contain elements

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 13, 2003
    #2
    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. Michael Reiche
    Replies:
    3
    Views:
    10,818
    Michael Reiche
    Feb 5, 2004
  2. Replies:
    2
    Views:
    376
  3. Replies:
    2
    Views:
    858
  4. eggie5
    Replies:
    1
    Views:
    525
    Joseph Kesselman
    Oct 2, 2007
  5. Dave Mathew
    Replies:
    0
    Views:
    852
    Dave Mathew
    Oct 6, 2008
Loading...

Share This Page