XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
nisha nickhilSubject: counter in xquery
Author: nisha nickhil
Date: 27 Mar 2007 11:47 AM
how do I have a counter in xquery, basically I want to do,

declare variable $counter=0;

for $i in (1, 2,.....)
$counter = $counter + 1;
return <value>{ $counter }</value>

Postnext
Tony LavinioSubject: counter in xquery
Author: Tony Lavinio
Date: 27 Mar 2007 11:54 AM
You almost had it.

for $i in (1 to 10)
return <value>{ $i }</value>

But you must stop thinking procedurally.
Variables don't change value in XQuery, just like they don't in XSLT.
But you can assign them to a whole sequence of values, including a
sequence of nodes.

Postnext
nisha nickhilSubject: counter in xquery
Author: nisha nickhil
Date: 27 Mar 2007 02:07 PM
Tony,
I will not know the range for $i, I really need a counter to use as prefix for a value.

Postnext
Tony LavinioSubject: counter in xquery
Author: Tony Lavinio
Date: 27 Mar 2007 04:34 PM
Then you're not thinking about the problem right.

Think about the result as a set, not as a list of
items to be iterated through.

The 'for' in XQuery doesn't mean 'walk through the
list of items matching the criteria one by one'.
Instead it means 'I've already selected the entire
set of data, now I'm going to apply some operation
to all of them.'

Maybe if you provided a little more information, such
as what your input looks like and what your output is
supposed to look like, we can help.

But trim it down to a nice simple case, please.

Posttop
Minollo I.Subject: counter in xquery
Author: Minollo I.
Date: 27 Mar 2007 04:41 PM
Something along these lines may help:

for $i at $pos in (1, 2, 3)
return <value>{ $pos }</value>

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.