Re: [xsl] Identity Transform

Subject: Re: [xsl] Identity Transform
From: Adam Turoff <ziggy@xxxxxxxxx>
Date: Mon, 22 Sep 2003 17:10:09 -0400
On Mon, Sep 22, 2003 at 08:28:57PM +0000, Abie Hamaoui wrote:
> hello there,
> why does the standard identity transform use copy instead of copy-of?
> ie:
>  <xsl:template match="/ | @* | node()">
>    <xsl:copy>
>      <xsl:apply-templates select="@* | node()"/>
>    </xsl:copy>
>  </xsl:template>
>
> instead of just
>  <xsl:template match="/">
>    <xsl:copy-pf select="."/>
>  </xsl:template>

xsl:copy-of is a deep copy of a node and its descendants.  using xsl:copy
instead recursively visits the entire document, while your xsl:copy-of
template visits only the root node and copies it in its entirety, as-is.

Using the identity transform, I can have other templates in my
stylesheet, such as:

	<!-- relabel <foo> to become <bar> -->
	<xsl:template match="foo">
	 <bar>
	  <xsl:apply-templates select="@* | node()"/>
	 </bar>
	</xsl:template>

	<!-- prune nodes -->
	<xsl:template match="text() | baz | quuz"/>

	<!-- copy children, selectively delete attributes -->
	<xsl:template match="para">
	 <xsl:copy>
	  <xsl:apply-templates select="@*[name(.) != 'id'] | node()"/>
	 </xsl:copy>
	</xsl:template>

Additionally, xsl:copy-of doesn't give the XSLT processor a chance
to do any optional decoration, like <xsl:output method="xml" indent="yes"/>

Z.


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


Current Thread