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

Re: Identity and Modified identity transforms

Subject: Re: Identity and Modified identity transforms
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 3 Dec 2007 12:23:45 +0000
Re:  Identity and Modified identity transforms
On 03/12/2007, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> > I don't know of the top of my head what node()[1] would do if
> > the currrent node was an attribute...
>
> Attributes don't have children, so child::node()[1] returns an empty
> sequence.

It seems:

<xsl:template match="@*|node()">
      <xsl:copy>
              <xsl:apply-templates select="@*|node()[1]"/>
      </xsl:copy>
      <xsl:apply-templates select="following-sibling::node()[1]"/>
</xsl:template>

...is fine because xsl:copy copies the entire attribute (name and value).

From: http://www.w3.org/TR/xslt20/#element-copy

"When the context item is an attribute node, text node, comment node,
processing instruction node, or namespace node, the xsl:copy
instruction returns a new node that is a copy of the context node. The
new node will have the same node kind, name, and string value as the
context node. In the case of an attribute node, it will also have the
same values for the is-id and is-idrefs  properties. The sequence
constructor, if present, is not evaluated."

So the two apply-templates instructions are redundant when the context
node is an attribute, making the above template compact but perhaps
inefficient.  The extra template in the two-template version could be
shortened ever so slightly to:

<xsl:template match="node()">
      <xsl:copy>
              <xsl:apply-templates select="@*|node()[1]"/>
      </xsl:copy>
      <xsl:apply-templates select="following-sibling::node()[1]"/>
</xsl:template>

<xsl:template match="@*">
      <xsl:copy/>
</xsl:template>



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.