parameter evaluates not to a node list

Discussion in 'XML' started by Paul Verbelen, Jun 14, 2006.

  1. 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>
     
    Paul Verbelen, Jun 14, 2006
    #1
    1. Advertising

  2. 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"
    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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 14, 2006
    #2
    1. Advertising

  3. 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
     
    Joe Kesselman, Jun 14, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,495
  2. mg

    Evaluates a supplied string

    mg, Dec 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    397
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,443
    Dimitre Novatchev
    Aug 24, 2006
  4. Eric Lilja
    Replies:
    3
    Views:
    340
    Gianni Mariani
    May 20, 2007
  5. Andrew
    Replies:
    5
    Views:
    267
    Peter Otten
    Nov 23, 2008
Loading...

Share This Page