Subject: Re: Is self() an attribute or element? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 15 Oct 1999 16:53:08 -0400 |
I have a template that is called to do default processing for a particular node. I'd like to be able to tell if the node is an attribute or element node. Any ideas?
T:\clark>type partlist.xml <?xml version="1.0"?> <!--start--> <part-list><part-name part-nbr="A123">bolt</part-name> <part-name part-nbr="B456">washer</part-name><warning type="ignore"/> <!--end of parts--><?cursor blinking?> </part-list> T:\clark>type shownode.xsl <?xml version="1.0"?> <!DOCTYPE xsl:stylesheet [<!ENTITY nl "
">]> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/|*|@*|processing-instruction()| comment()|text()"> <xsl:variable name="this-node" select="generate-id(.)"/> <xsl:variable name="this-type"> <xsl:for-each select="../*"> <xsl:if test="generate-id(.)=$this-node">Element</xsl:if> </xsl:for-each> <xsl:for-each select="../@*"> <xsl:if test="generate-id(.)=$this-node">Attribute</xsl:if> </xsl:for-each> <xsl:for-each select="../processing-instruction()"> <xsl:if test="generate-id(.)=$this-node">PI</xsl:if> </xsl:for-each> <xsl:for-each select="../comment()"> <xsl:if test="generate-id(.)=$this-node">Comment</xsl:if> </xsl:for-each> <xsl:for-each select="../text()"> <xsl:if test="generate-id(.)=$this-node">Text</xsl:if> </xsl:for-each> <xsl:if test="not(..)"> <xsl:text>Root</xsl:text> </xsl:if> </xsl:variable> <xsl:text>&nl;Node </xsl:text><xsl:value-of select="name(.)"/> <xsl:text> is a node of type: </xsl:text> <xsl:value-of select="$this-type"/> <xsl:if test="string($this-type)='Attribute'"> <xsl:text> (BINGO!! Found an attribute)</xsl:text> </xsl:if> <xsl:apply-templates select="*|@*|processing-instruction()| comment()|text()"/> </xsl:template>
</xsl:stylesheet> T:\clark>xt partlist.xml shownode.xsl
Node is a node of type: Root Node is a node of type: Comment Node part-list is a node of type: Element Node part-name is a node of type: Element Node part-nbr is a node of type: Attribute (BINGO!! Found an attribute) Node is a node of type: Text Node is a node of type: Text Node part-name is a node of type: Element Node part-nbr is a node of type: Attribute (BINGO!! Found an attribute) Node is a node of type: Text Node warning is a node of type: Element Node type is a node of type: Attribute (BINGO!! Found an attribute) Node is a node of type: Text Node is a node of type: Comment Node cursor is a node of type: PI Node is a node of type: Text T:\clark>
-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML services, training, libraries, products. Practical Transformation Using XSLT and XPath ISBN 1-894049-02-0 Next instructor-led training: 1999-11-08, 1999-11-09, 1999-12-05/06, 1999-12-07, 2000-02-27/28, 2000-05-11/12
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: ;) Is self() an attribute or el, G. Ken Holman | Thread | Re: replacing characters in a strin, Christopher R. Maden |
Re: Nostradamus (was Re: FO. lists , Steve Schafer | Date | Re: replacing characters in a strin, Christopher R. Maden |
Month |