Subject: Re: ;) Is self() an attribute or element? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 15 Oct 1999 16:25:24 -0400 |
<xsl:if test="../@*=.">I am an attribute</xsl:if>
On Fri, 15 Oct 1999, Clark C. Evans wrote: > 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 clark.xml <?xml version="1.0"?> <test attr="hello"><junk>hello</junk></test> T:\clark>type clark1.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="/"> <xsl:text>&nl;Element:&nl;</xsl:text> <xsl:for-each select="/*/*"> <xsl:if test="../@*=.">I am an attribute</xsl:if> </xsl:for-each> <xsl:text>&nl;Attribute:&nl;</xsl:text> <xsl:for-each select="/*/@*"> <xsl:if test="../@*=.">I am an attribute</xsl:if> </xsl:for-each> </xsl:template>
Element: I am an attribute Attribute: I am an attribute T:\clark>type clark2.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="/"> <xsl:text>&nl;Element:&nl;</xsl:text> <xsl:for-each select="/*/*"> <xsl:if test="not(self::*)">I am an attribute</xsl:if> </xsl:for-each> <xsl:text>&nl;Attribute:&nl;</xsl:text> <xsl:for-each select="/*/@*"> <xsl:if test="not(self::*)">I am an attribute</xsl:if> </xsl:for-each> </xsl:template>
Attribute: I am an attribute 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 -> |
---|---|---|
;) Is self() an attribute or elemen, Clark C. Evans | Thread | Re: Is self() an attribute or eleme, G. Ken Holman |
;) Is self() an attribute or elemen, Clark C. Evans | Date | Re: Nostradamus (was Re: FO. lists , Steve Schafer |
Month |