Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > parameter evaluates not to a node list

Reply
Thread Tools

parameter evaluates not to a node list

 
 
Paul Verbelen
Guest
Posts: n/a
 
      06-14-2006
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-14-2006


Paul Verbelen wrote:
> 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-comslt">

<xslutput 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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      06-14-2006
Paul Verbelen wrote:
> <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/


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
imported method from module evaluates to None in some cases Andrew Python 5 11-23-2008 11:23 AM
Using operator new in function call and what the expr evaluates to Eric Lilja C++ 3 05-20-2007 08:29 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Evaluates a supplied string mg ASP .Net 0 12-23-2003 07:30 PM



Advertisments