[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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: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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Checking element to see i, Jarno . Elovirta | Thread | RE: [xsl] Checking element to see i, Lars Huttar |
Re: [xsl] Checking element to see i, JCS | Date | [xsl] Announce: Hands-on XSL traini, G. Ken Holman |
Month |
Keywords