[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: ;) Is self() an attribute or element?
At 99/10/15 15:16 -0400, Clark C. Evans wrote:
<xsl:if test="../@*=.">I am an attribute</xsl:if> Sorry, Clark, but I can contrive an example where the test you've designed will fail. You are relying on content, not checking for the type of node. I suggest you use: test="not(self::*)" which is to say "I am not a node whose self is any element". Now my test will *only* tell you it isn't an element node, it doesn't really test that the node is an attribute node, as it could be any other kind of non-element node. I'll post that kind of test separately. I've illustrated the contrivance below ... I hope this helps. ......... Ken 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:output method="text"/> <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> </xsl:stylesheet> T:\clark>xt clark.xml clark1.xsl 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:output method="text"/> <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> </xsl:stylesheet> T:\clark>xt clark.xml clark2.xsl Element: 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 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
|