Re: [xsl] Result tree fragment to string?

Subject: Re: [xsl] Result tree fragment to string?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Thu, 28 Aug 2008 12:31:27 +0200
Houghton,Andrew wrote:

The above doesn't handle namespaces, processing-instructions,
comments,
or mixed content, but it could be hacked to do so.  Is there a reason
why this approach would not work in XSL 1.0 to satisfy his needs?
Yes, the reason is that you can't do the apply-templates on the result
tree fragment, you would first need to convert it to a node-set with an
extension function.

Oops, I thought his result tree was a node set, not a string...

A result tree fragment is not a string but it is also not a node set.


If you have e.g.

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

  <xsl:template match="/">
    <xsl:variable name="rtf">
      <html>
        <body>
          <p>Example</p>
        </body>
      </html>
    </xsl:variable>
    <xsl:apply-templates select="$rtf" mode="m1"/>
  </xsl:template>

  <xsl:template match="/" mode="m1">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

then for instance Saxon 6.5 will complain "Error at xsl:apply-templates on line 13 [...]. Cannot process a result tree fragment as a node-set under XSLT 1.0".

--

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

Current Thread