Re: [xsl] Checking element to see if it has children...

Subject: Re: [xsl] Checking element to see if it has children...
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 02:32:33 +1300
Hi Jarno,

Thanks for the response. I did check the FAQ again under "Empty Elements" to
see about element checking. I think I ran into one those XSL "snafus"
because when I ran a test to see if elements didn't have children, I didn't
get any output when selecting ancestor::* (just the tests for "yes" came
through). My head is still having a little trouble with this...

But using the following stylesheet & data:

<xsl:template match="/">

    <xsl:for-each select="/*//*">
        <xsl:call-template name="path"/>

<xsl:template name="path">

<!--this is selecting the ancestors of current node-->
<xsl:for-each select="ancestor::*">
          <xsl:when test="not(node())">
        Not node: <xsl:value-of select="name()"/> has no children:
          <xsl:when test="node()">
            <font color="blue">
                <xsl:value-of select="name()"/>

    <font color="red">
        <xsl:value-of select="name()"/>





I get the following:

root /element_one 
root /element_two 
root /element_three
root /element_four 
root /element_four /element_four_one

But I would like the output to be:

root /element_one 
root /element_two 
root /element_three
root /element_four /element_four_one

Because ³element_four² is a container and has no text, it shouldn¹t be a red

Also, I tried running this template on a 1MB file, just to prove I¹m related
to Forrest Gump, and it took over three minutes to process. So I¹m imagining
that I could use a key in here to speed up the process. Then there¹s that
lovely part about removing duplicates once the pattern repeats itself...

/johnny :)

On 10/12/03 1:30 AM, "Jarno.Elovirta@xxxxxxxxx" <Jarno.Elovirta@xxxxxxxxx>

> FAQ,
>> For starters I've been trying to figure out how to check to see if an
>> element contains elements (has child element nodes) but I'm--stumped.
> Try to select it
> <xsl:if test="*">
>   ...
> </xsl:if>
> Cheers,
> Jarno - Blank: Overhead (Extended)
> XSL-List info and archive:

The aging process has you firmly in its grasp if you never get the urge to
throw a snowball. 
-- Doug Larson 

 XSL-List info and archive:

Current Thread