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

Subject: [xsl] Checking element to see if it has children...
From: JCS <subscriber@xxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 01:04:59 +1300
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