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

RE: The identity transform and attributes

Subject: RE: The identity transform and attributes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 21 Jan 2008 11:03:06 -0000
RE:  The identity transform and attributes
I wouldn't expect any measurable performance difference, but if you feel it
adds clarity (or reusability) then go ahead. Perhaps even more logical would
be:

<xsl:template match="element()">
    <xsl:copy>
        <xsl:apply-templates select="@*,node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="attribute()|text()|comment()|processing-instruction()">
    <xsl:copy/>
</xsl:template> 

(The "," in place of "|" is a minor optimization that recent Saxon releases
do anyway - it avoids an unnecessary merge/deduplication of the sequence of
attributes with the sequence of children.)

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx] 
> Sent: 21 January 2008 10:29
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  The identity transform and attributes
> 
> I'm wondering if the default identity transform should be this:
> 
> <xsl:template match="@*|node()">
>     <xsl:copy>
>         <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
> </xsl:template>
> 
> Or this:
> 
> <xsl:template match="node()">
>     <xsl:copy>
>         <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
> </xsl:template>
> 
> <xsl:template match="@*">
>     <xsl:copy/>
> </xsl:template>
> 
> The former is nice and compact, but when the node is an 
> attribute node does the apply-templates call have any effect 
> - even if it's a few clock cycles wasted?  It's a pointless 
> instruction at that point.  I guess it is too for non-element 
> node()'s such as whitespace?
> 
> Also, the shallow copy copies the entire attribute, so there 
> is no opportunity to override the text() of the attribute.  
> The only way is to add a separate matching template for the 
> attribute - the latter perhaps makes this a little clearer.
> 
> A useful distinction or a waste of time? :)
> 
> cheers
> --
> Andrew Welch
> http://andrewjwelch.com
> Kernow: http://kernowforsaxon.sf.net/

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.