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

H

Hannes Heckner

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
 
M

Martin Honnen

Hannes said:
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top