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

Re: ;) Is self() an attribute or element?

Subject: Re: ;) Is self() an attribute or element?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Oct 1999 16:25:24 -0400
what element am i test
At 99/10/15 15:16 -0400, Clark C. Evans wrote:

<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?

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 "&#xd;&#xa;">]>
<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 "&#xd;&#xa;">]>
<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



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.