Subject: Re: [xsl] <xsl:for-each select="$myvar"> From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 19 Jun 2002 15:49:25 +0100 |
Hi William, > I am trying to do the operation as described in the subject > line but am getting "Sablotron Error (48): > expression is not a node set". > > The value of the variable is "item" which is the same as if > I used "<xsl:for-each select="item">" So why > doesnt this work? It's very hard to tell, since you haven't shown us the XSLT that you're using. My first guess is that you're setting the variable using either: <xsl:variable name="myvar"> <xsl:value-of select="item" /> </xsl:variable> or possibly: <xsl:variable name="myvar"> <xsl:copy-of select="item" /> </xsl:variable> Both of these set the $myvar variable to a result tree fragment (a small result tree, with its own root node, containing either the value of the first item [in the first case] or copies of the item elements [in the second case]) rather than to a node set. To set the variable to a node set instead, use the select attribute of xsl:variable as follows: <xsl:variable name="myvar" select="item" /> My second guess is that you're setting the variable to a string as in: <xsl:variable name="myvar" select="'item'" /> or maybe: <xsl:variable name="myvar">item</xsl:variable> In this case, you want to evaluate the $myvar variable as an XPath expression. In this simple case, where you're only using the name of the element you want to select, you can use: <xsl:for-each select="*[name() = $myvar]"> ... </xsl:for-each> For the general case (such as displaying only DEC machines, which involves using predicates), you need to use an extension function, and I don't think that Sablotron supports such an extension function, which means you'd have to write your own, and then do something like: <xsl:for-each select="my:evaluate($myvar)"> ... </xsl:for-each> (Perhaps base your evaluate() function around dyn:evaluate(), described at http://www.exslt.org/dyn/functions/evaluate/ as that's a kind of standard.) Alternatively, you can make the process into a two-step process where you first generate a stylesheet that includes the path, and then use that stylesheet on the source XML document to create the result. This might be simpler... Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] <xsl:for-each select="$my, David Carlisle | Thread | Re: [xsl] <xsl:for-each select="$my, Vasu Chakkera |
Re: [xsl] Hello World, Thomas B. Passin | Date | Re: [xsl] counting average value, James Fuller |
Month |