Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Identity and Modified identity transforms

From: "Andrew Welch" <andrew.j.welch@--------->
To:
Date: 12/3/2007 12:24:00 PM
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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent