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

Checking element to see if it has children...

Subject: Checking element to see if it has children...
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 01:04:59 +1300
foo man chu
Hi everyone,

I'm trying to write a stylesheet to process any XML file and give me the
path/element stack as follows:

root/foo/manchu/chocolate/bar
root/foo/manchu/chocolate/cake/icing
root/foo/manchu/chocolate/brownie

Etc.

I've easily constructed a template that gives me what I want as such:

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

<xsl:template name="path">
    <xsl:for-each select="ancestor::*">
        <xsl:value-of select="name()"/>
        <xsl:text>/</xsl:text>
    </xsl:for-each>
    <xsl:value-of select="name()"/>
    <br/>
</xsl:template>  

And this gives me what I want EXCEPT:

I obviously get duplicates because it gives me all the elements. I've been
reading the archives to try to find out how to remove duplicates, this seems
non-trivial and a bit difficult,

I want the path to end with the element only if it doesn't contain other
elements, i.e. what railroad fans might call a "stub":

foo/bar/stub <--this element has no children
foo/bar/stub/yes <-- here stub actually contains children

In other words, if "stub" contains children, it shouldn't be a stub, but
that's what I currently get using my template.

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.

I've looked in the archives under "node testing" and element manipulation
but I'm not sure what I'm looking for.

Any help would be appreciated,

TiA,

/johnny :)







-- 
Planting a seed doesn't make it grow.
-- Sass Jordan 


 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.