[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Testing the type of the current node
Hi Can anyone tell me what is wrong with the following stylesheet? In the "analyse_node" (I speak English, not American) template I'm trying to determine the type of the current node and print out an appropriate message. Currently only the element test self::* works. I would have thought that self::text() would return true if the current node was text - but it keeps passing straight through to the <xsl:otherwise> branch. Thanks in advance. ---- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:template name="indent"> <xsl:param name="indent" /> <xsl:if test="$indent > 0"> <xsl:text> </xsl:text> <xsl:call-template name="indent"> <xsl:with-param name="indent" select="$indent - 1" /> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="analyse_node"> <xsl:param name="indent" /> <xsl:call-template name="indent"> <xsl:with-param name="indent" select="$indent" /> </xsl:call-template> <xsl:for-each select="child::node()"> <xsl:choose> <xsl:when test="self::*"> <xsl:text>ELEMENT : `</xsl:text> <xsl:value-of select="name(.)" /> <xsl:text>' </xsl:text> <xsl:call-template name="analyse_node"> <xsl:with-param name="indent" select="$indent + 1" /> </xsl:call-template> </xsl:when> <xsl:when test="self::text()"> <xsl:text>TEXT : `</xsl:text> <xsl:value-of select="." /> <xsl:text>' </xsl:text> </xsl:when> <xsl:when test="self::comment()"> <xsl:text>COMMENT : `</xsl:text> <xsl:value-of select="." /> <xsl:text>' </xsl:text> </xsl:when> <xsl:when test="self::processing-instruction()"> <xsl:text>PI : `</xsl:text> <xsl:value-of select="." /> <xsl:text>'</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>UNKNOWN OBJECT : ` </xsl:text> <xsl:value-of select="." /> <xsl:text>' </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> <xsl:template match="/"> <xsl:call-template name="analyse_node"> <xsl:with-param name="indent" select="0" /> </xsl:call-template> </xsl:template> </xsl:stylesheet> -- Warren Hedley Department of Engineering Science Auckland University New Zealand 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
|