xsl-list
[Top] [All Lists]

Re: [xsl] Identity and Modified identity transforms

2007-12-03 05:24:18
On 03/12/2007, Michael Kay <mike(_at_)saxonica(_dot_)com> 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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--