[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Testing the type of the current node
> I'm trying to determine the type of the current node and print > out an appropriate message. I think (someone please prove me wrong) it is impossible to do this directly. What you can do, however, is this: nodetype.xsl: ============= <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="node-type"> <xsl:param name="node" select="."/> <xsl:apply-templates mode="nodetype" select="$node"/> </xsl:template> <xsl:template mode="nodetype" match="*">element</xsl:template> <xsl:template mode="nodetype" match="@*">attribute</xsl:template> <xsl:template mode="nodetype" match="text()">text</xsl:template> </xsl:stylesheet> test.xsl: ========= <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="nodetype.xsl"/> <xsl:template match="/"> <xsl:for-each select="//node()|//@*"> <xsl:variable name="node-type"> <xsl:call-template name="node-type"/> </xsl:variable> <xsl:message>Node is of type: <xsl:value-of select="$node-type" /></xsl:message> </xsl:for-each> </xsl:template> </xsl:stylesheet> test.xml: ========= <test> <elem type="attr">hello</elem> world </test> output: ======= $do-saxon2 test.xml test.xsl Node is of type: element Node is of type: text Node is of type: element Node is of type: attribute Node is of type: text Node is of type: text In Real Life(TM), you can just test the string value in your xsl:choose instead of testing the node type directly. Steve 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
|