xsl-list
[Top] [All Lists]

Re: [xsl] Capturing result of <xsl:apply-templates/> in a variable

2011-12-06 14:27:47
Right... in the example I gave, the template will always return at least an element, but I should have generalized for null results.

On Tue, 6 Dec 2011, David Carlisle wrote:

On 06/12/2011 19:52, David Sewell wrote:
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:apply-templates/>
</xsl:variable>
the + there means this will generate an error if the apply-templates generates no output, whereas the original version would just silently produce nothing. a * would allow this empty result.

David



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

--~------------------------------------------------------------------
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>
--~--