XSLT: Result trees in variables

A

Aleksi Kallio

I'm passing a result tree fragment that holds multiple strings
(fieldnames, in this case) and in the called template I wan't to test if
a certain string contains any of those names.

I have this:

<xsl:apply-templates select="field">
<xsl:with-param name="element-names">
<names>
<name>foo</name>
<name>bar</name>
</names>
</xsl:with-param>
</xsl:apply-templates>

....

<xsl:template match="field">
<xsl:param name="element-names" />

<xsl:variable name="search-element-names">
<result>
<xsl:for-each select="$element-names/names/name">
<xsl:if test="contains('foobar', text())">.</xsl:if>
</xsl:for-each>
</result>
</xsl:variable>

<xsl:variable name="search-condition" select="$search-element-names =
''" />


I get this:

Can not convert #RTREEFRAG to a NodeList!


What is the parser trying to say to me?

Any ideas how to fix it?
 
P

Patryk Dworznik

I get this:

Can not convert #RTREEFRAG to a NodeList!


What is the parser trying to say to me?

Any ideas how to fix it?

Passing a fragment of XML tree to a variable you get a data
type called Result Tree Fragment, which is quite useful
to store chunks of XML tree but fails when used in an xpath expression.
To get this working you must convert rtf back to a node set by
applying the extension function node-set().
In order to use this you must first declare a proper extension namespace
in your stylesheet. Most likely your processor supports exslt:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl" >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top