[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: <xsl:for-each select="$myvar">

Subject: Re: <xsl:for-each select="$myvar">
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 19 Jun 2002 15:49:25 +0100
xsl variable for each select
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.