Subject: Re: XSLT 1.0: How to apply-templates while copying the content of a template parameter?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Sep 2009 10:17:39 -0400
|
Alain,
By way of background to what Martin has told you: this XSLT feature,
namely transparent processing of (temporary) results, is possibly the
most important single difference between XSLT 1.0 and XSLT 2.0. In
XSLT 2.0, what you are trying (or something very like it) would just
work. In XSLT 1.0, there is a restriction -- the definition of the
"result tree fragment" object that Martin mentions (which can be
copied, or evaluated as a string, but not processed as a tree) --
that prohibits it.
This is why an extension function is necessary in XSLT 1.0. And why
so many processors offer this particular functionality by way of an extension.
Cheers,
Wendell
At 06:11 AM 9/10/2009, you wrote:
Alain Gilbert wrote:
I have the simplified stylesheet that follows this message. I have
a problem with the usage of the "addInlineText" template which
simply tries to copy the nodes defined at the call site. It is also
important to apply-template on the copied nodes to further apply
transformations defined elsewhere.
Xalan fails to process the template and seems to fail to build a
node-set for the for-each instruction. I get this error:
SystemID: print.xsl; Line#: 9; Column#: 33
org.apache.xpath.XPathException: Can not convert #RTREEFRAG to a NodeList!
The error tells you that you have a result tree fragment that needs
to be converted into a node-set. With the result tree fragment you
can only do xsl:copy-of or xsl:value-of.
You can use the exsl:node-set function for converting the result
tree fragment into a node-set:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml" version="1.0"
exclude-result-prefixes="html">
Add
xmlns:exsl="http://exslt.org/common"
here on the xsl:stylesheet element. And then you will probably want
to list the prefix exsl in the exclude-result-prefixes attribute as well.
<xsl:template name="addInlineText">
<xsl:param name="value" />
<xsl:for-each select="$value" >
I think here you need
<xsl:for-each select="exsl:node-set($value)">
then you should no longer get the error you described above.
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
|