Re: [xsl] xpath query

Subject: Re: [xsl] xpath query
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 19 Jan 2008 18:57:02 +0100
Sean Tiley wrote:

2) - Also related to the first template. Why do I need the
<xsl:template match="@* | node()"> and
<xsl:apply-templates select="@* | node()"/> in the <xsl:copy/> tag?
I would have thought in the template match "/" would have sufficed.
(When I try that, I just get the values from the nodes).

Well if you want to copy everything (the XSLT data model covers) then
<xsl:template match="/">
<xsl:copy-of select="/"/>
</xsl:template>
suffices but that is not an approach where you can work in additional templates. With the identity transformation template written as
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
you can add templates to override the template for nodes that you want to change. So using xsl:copy for a shallow copy and xsl:apply-templates to process attributes and child elements gives additional templates a chance to be applied on each step.



--


	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread