[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Checking element to see if it has children...
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|