[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Capturing result of in a variable


Subject: Re: [xsl] Capturing result of <xsl:apply-templates/> in a variable
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 06 Dec 2011 20:08:04 +0000

This was probably the first time in my years of working with XSLT that it occurred to me to capture <xsl:apply-templates/> in a variable (I'll never be an XSLT wizard). I'm wondering: is the procedure above guaranteed to work in all cases, or is it possible that the <xsl:copy-of select="$appliedTemplates"/> could ever return something different from <xsl:apply-templates/> in this context?
Doing xsl:copy-of on the variable is perfectly safe. Doing apply-templates or other processing on it can be risky - because the copied nodes differ from the original by having fewer ancestors, so logic that looks outside the immediate subtree will behave differently.

On a related point, people often use xsl:message to produce diagnostic output. I often find it more helpful to put the diagnostic data in the result document itself, so you'll see me writing stuff like

<xsl:variable name="v" select="....."/>
<debug var="$v">
<xsl:copy-of select="$v"/>
</debug>

Michael Kay
Saxonica


Current Thread
Keywords