[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Capturing result of <xsl:apply-templates/> in a variab

Subject: Capturing result of <xsl:apply-templates/> in a variable
From: David Sewell <dsewell@xxxxxxxxxxxx>
Date: Tue, 6 Dec 2011 14:52:07 -0500 (EST)
 Capturing result of <xsl:apply-templates/> in a variab
Just now when writing a transform, for temporary diagnostic purposes I needed to produce messages showing (1) the initial string value of an input element before template application, and (2) the output string value after template application. Oddly enough I have never before wanted to do precisely that task.

A moment's reflection suggested that I could capture the result of <xsl:apply-templates/> and use it as a variable, thus (given XSLT 2.0):

<xsl:template match="INPUT">
  <xsl:variable name="appliedTemplates" as="item()+">
    <xsl:copy-of select="$appliedTemplates"/>
  <xsl:message>Old value: <xsl:value-of select="."/></xsl:message>
  <xsl:message>New value: <xsl:value-of select="$appliedTemplates"/></xsl:message>

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? And is this the best strategy for comparing input and output states of a template (assuming string value is the only concern)?

David S.

David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville, VA 22904-4314 USA
Email: dsewell@xxxxxxxxxxxx   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.