[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Testing the type of the current node

Subject: Re: Testing the type of the current node
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Fri, 24 Mar 2000 00:12:42 -0500
nodetype xsl
> 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.