[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Checking element to see if it has children...

Subject: Re: Checking element to see if it has children...
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 02:32:33 +1300
xsl has child
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:for-each>
 
</xsl:template>  

<xsl:template name="path">

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

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

</xsl:stylesheet> 

----------

<root>
<element_one>one</element_one>
<element_two>two</element_two>
<element_three>thing</element_three>
<element_four>
    <element_four_one>
    </element_four_one>
</element_four>
</root>

------------

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
³stub².

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>
wrote:

> 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:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 

-- 
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:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.