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

RE: Cannot select a node here: the context item is an

Subject: RE: Cannot select a node here: the context item is an atomic value
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Apr 2005 18:28:51 +0100
xpath select date
You'll need to set a variable outside the outer loop, and in the inner loop
do something like

<xsl:for-each select="$s/my/xpath/query[@day=$day]">

In fact, you might as well select the whole path in the variable and just
use

<xsl:for-each select="$s[@day=$day]"> 

I would tend to use .-1 rather than position()-1, but the effect is the
same. Actually, I would probably not build the duration from a string, but
rather from:

<xsl:variable name="one-day" select="xs:dayTimeDuration('P1D')"/>  (global
variable)

then in the loop:
<xsl:variable name="day" select=". * $one-day"/>

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: chris [mailto:oneskiingfool@xxxxxxxxx] 
> Sent: 05 April 2005 18:11
> To: xslt
> Subject:  Cannot select a node here: the context item is 
> an atomic value
> 
> Hello,
> I'm using XSLT/XPath 2.0 and am stuck on a very basic problem again. 
> All I want to do is nest my for-each loop inside another loop so that
> the inner for-each loops executes x number of times.
> To be more specific, I'm creating an HTML table with dates running
> down the left column and corresponding values in the rest of the
> cells.
> So I have date range: $date1 to $date2
> I calculated the number of days between the two: $dayCount
> 
> <xsl:for-each select="1 to $dayCount">
>    <xsl:variable name="day" select="($date1+
> xdt:dayTimeDuration(concat('P',position()-1,'D')))"/>
>    <tr>
>      <td>
>        <xsl:value-of 
> select="format-dateTime($day,'[Y,*-2]-[M,2]-[D,2]')"/>
>      </td>
>      <xsl:for-each select="my/xpath/query[@day=$day]">
>        <td>
>           <xsl:value-of select="."/>
>        </td>
>      </xsl:for-each>
>    </tr>
> </xsl:for-each>
> 
> 
> The inner loop gives me this error:
> Cannot select a node here: the context item is an atomic value
> 
> Could somebody kindly let me know how to do this?  It's clearly stated
> in the documentation that I can't do it this way (nest node loops in
> atomic loops), but I don't see a workaround.
> 
> P.S. Also any hints if there is a better way to do that outer loop
> would be appreciated as well.
> 
> Thanks!

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.