Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath: How to select all nodes which don't have children`

Reply
Thread Tools

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

 
 
Hannes Heckner
Guest
Posts: n/a
 
      10-13-2003
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-13-2003


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/

 
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
XSL select only nodes which contain a specific child node William Krick XML 4 03-18-2011 09:54 AM
Using a variable to tell xsl:for-each which nodes to select cosmo XML 0 10-04-2008 06:14 AM
xpath select all nodes under document root eggie5 XML 1 10-02-2007 07:43 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
implement "select all" button to select all checkboxes Matt ASP General 2 01-11-2004 01:08 PM



Advertisments