This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Exclude Attributes from select?


At 00/10/13 13:29 +0200, Linda van den Brink wrote:
> > If i use <xsl:copy-of select="@*">, is there a possibility,
> > to exclude some attributes?
>
>You could use something like
>
>xsl:copy-of select="@*[not(self::attrib1)]"
>
>Linda



I very much apologize if this sounds pedantic, but the incorrect answer to 
this question was given twice by different people, so I will respond to 
each with the same answer in case people hunt down one thread but not the 
other.

The self:: axis cannot be used as shown above, because the principal node 
type along the self:: axis is element and when only a name is given in the 
node test only nodes of the principal type are returned.  One might ask 
"since I'm on the attribute axis, why isn't the attribute the principal 
node type in the predicate" ... the answer is because XSLT states that if 
an axis is allowed to have elements along it, as does the self:: axis, then 
the element is the principal node type.  Therefore, since there are no 
elements on the attribute axis, nothing is ever returned from the self:: 
axis in the above expression.

The only way I can see to exclude particular attributes is with the name() 
function.

An illustration is below.

I hope this helps, and again, sorry for duplication but I understand one's 
intuition to try the above and I think it is important to cover the bases.

...................... Ken

p.s. for those of you who have the Eighth Edition of our book, the summary 
is on page 70.

T:\ftemp>type test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:dummy="dummy"
                 exclude-result-prefixes="dummy"
                 version="1.0">

<xsl:output method="text"/>

<dummy:data>
   <hello att1="att1-val" att2="att2-val" att3="att3-val"/>
</dummy:data>

<xsl:template match="/">                         <!--root rule-->
   <xsl:for-each select="document('')//hello">
     <xsl:text>Using self::</xsl:text>
     <xsl:for-each select="@*[not(self::att2)]" xml:space="preserve">
       <xsl:value-of select="name(.)"/>-<xsl:value-of select="."/>
     </xsl:for-each>
     <xsl:text>&#xa;Using self::</xsl:text>
     <xsl:for-each select="@*[name(.)!='att2']" xml:space="preserve">
       <xsl:value-of select="name(.)"/>-<xsl:value-of select="."/>
     </xsl:for-each>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\ftemp>xt test.xsl test.xsl
Using self::
       att1-att1-val

       att2-att2-val

       att3-att3-val

Using self::
       att1-att1-val

       att3-att3-val

T:\ftemp>


--
G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com
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.
Book: Practical Transformation Using XSLT and XPath ISBN1-894049-05-5
Article:          What is XSLT? http://www.xml.com/pub/2000/08/holman
Next public instructor-led training:     2000-10-03/05,2000-10-09/10,
-        2000-10-19,2000-11-06/07,2000-11-12,2000-12-03/04,2001-01-27


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]