You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Ma...@tivoli.com on 2001/10/16 15:26:56 UTC
variable in select do not work
Hi everybody,
I've a problem that I've reproduced with the following stilesheet:
The following works:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="catalog"/>
</xsl:template>
<xsl:template match="catalog">
<xsl:variable name="books" select="book"/>
Number of books: <xsl:value-of select="count($books)"/>
</xsl:template>
</xsl:stylesheet>
the following give the error: Can not convert #RTREEFRAG to a NodeList!
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="parm">book</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="catalog"/>
</xsl:template>
<xsl:template match="catalog">
<xsl:variable name="books" select="$parm"/>
Number of books: <xsl:value-of select="count($books)"/>
</xsl:template>
</xsl:stylesheet>
(See attached file: sample.xml)
My real code take parm as parameter, but it gives the same error.
I was expecting that <xsl:variable name="books" select="$parm"/> returned
a nodset that I could pass to the count() function, but I was wrong!!
Any hint?
thanks a lot Maria
RE: variable in select do not work
Posted by Gary L Peskin <ga...@firstech.com>.
The variable named "parm" is a Result Tree Fragment and cannot be
converted to an XSLT node-set. To get what you want, try
<xsl:variable name="parm" select="'books'" />
Note the inner quotes on the select attribute making books a string.
For more info on this, see
http://www.w3.org/TR/xslt#section-Result-Tree-Fragments and the
following section.
Gary
> -----Original Message-----
> From: Maria_Baldassarri@tivoli.com
> [mailto:Maria_Baldassarri@tivoli.com]
> Sent: Tuesday, October 16, 2001 6:27 AM
> To: xalan-dev@xml.apache.org
> Subject: variable in select do not work
>
>
> Hi everybody,
> I've a problem that I've reproduced with the following
> stilesheet: The following works:
>
> <?xml version='1.0'?>
> <xsl:stylesheet version="1.0" xmlns:xsl
> ="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="/">
> <xsl:apply-templates select="catalog"/>
> </xsl:template>
>
> <xsl:template match="catalog">
> <xsl:variable name="books" select="book"/>
> Number of books: <xsl:value-of select="count($books)"/>
> </xsl:template>
>
> </xsl:stylesheet>
>
> the following give the error: Can not convert #RTREEFRAG to a
> NodeList!
>
> <?xml version='1.0'?>
> <xsl:stylesheet version="1.0" xmlns:xsl
> ="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:variable name="parm">book</xsl:variable>
>
> <xsl:template match="/">
> <xsl:apply-templates select="catalog"/>
> </xsl:template>
>
> <xsl:template match="catalog">
> <xsl:variable name="books" select="$parm"/>
> Number of books: <xsl:value-of select="count($books)"/>
> </xsl:template>
>
> </xsl:stylesheet>
>
> (See attached file: sample.xml)
>
> My real code take parm as parameter, but it gives the same
> error. I was expecting that <xsl:variable name="books"
> select="$parm"/> returned a nodset that I could pass to the
> count() function, but I was wrong!! Any hint?
>
> thanks a lot Maria
>