parameter evaluates not to a node list

P

Paul Verbelen

When I run this XSL with IE6 then I get following
error: "Reference to variable or parameter 'myset'
must evaluate to a node list." Why is 'myset' not
a node list?

How can this easely be solved?

---- XML file ---

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<root>
</root>

--- XSL file ---

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

<xsl:eek:utput method="xml" version="1.0"/>

<xsl:template match="/">

<xsl:variable name="myset">
<test>
</test>
</xsl:variable>

<xsl:value-of select="count($myset)"/>

</xsl:template>
</xsl:stylesheet>
 
M

Martin Honnen

Paul said:
When I run this XSL with IE6 then I get following
error: "Reference to variable or parameter 'myset'
must evaluate to a node list." Why is 'myset' not
a node list?
<xsl:variable name="myset">
<test>
</test>
</xsl:variable>

<xsl:value-of select="count($myset)"/>

Unfortunately XSLT 1.0 distinguishes between the data model for input
XML and result XML and your variable defines a result tree fragment on
which you can do e.g.
<xsl:copy-of select="$myset" />
but on which you can't apply the full XPath set of operations.

One way to solve that is to use an extension function, MSXML 3 and later
support one so you can do e.g.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:eek:utput method="xml" version="1.0"/>

<xsl:template match="/">

<xsl:variable name="myset">
<test>
</test>
</xsl:variable>

<xsl:value-of select="count(msxsl:node-set($myset))"/>

</xsl:template>
</xsl:stylesheet>

But obviously that approach is not portable as that extension function
namespace is Microsoft specific. Most XSLT processors by now provide a
similar extension function. Others do not.
 
J

Joe Kesselman

Paul said:
<xsl:variable name="myset">
<test>
</test>
</xsl:variable>

<xsl:value-of select="count($myset)"/>

You have put a Result Tree Fragment into the variable. Unfortunately, in
XSLT 1.0, RTFs are not nodesets and can't be navigated as trees. (XSLT
2.0 fixes this by replacing the concept of RTFs with "temporary trees").

The standard workaround for 1.0 is to use the EXSLT extension function
node-set(), if your processor supports it. (Most do, these days.)

http://www.exslt.org/exsl/functions/node-set/
 

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

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top