Break loop in XQuery

View: New views
5 Messages — Rating Filter:   Alert me  

Break loop in XQuery

by Edimar Manica :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

My name is Edimar Manica and I am a master degree student in the Federal University of Rio Grande do Sul - Brazil.

Is there break loop in XQuery in the eXist?

Something like:

 for $d in (1, 2, 5, 3, 0, 6, 3, 5)
   return 
   if ($d = 0) then break
   else $d


-------------------------------------------
Att. Edimar Manica
Mestrando em Ciência da Computação pela UFRGS
Área: Banco de dados
Orientadora: Renata Galante
Currículo: http://lattes.cnpq.br/7497320738069454

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Break loop in XQuery

by Adam Retter-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perhaps there is a better way of writing your query? What are you
trying to achieve exactly that has led you to this squeeze?

Also the xquery-talk mailing list may be a better place to ask such questions...

2009/11/11 Edimar Manica <edimarmanica@...>:

> Hi,
>
> My name is Edimar Manica and I am a master degree student in the Federal
> University of Rio Grande do Sul - Brazil.
>
> Is there break loop in XQuery in the eXist?
>
> Something like:
>
>  for $d in (1, 2, 5, 3, 0, 6, 3, 5)
>    return
>    if ($d = 0) then break
>    else $d
>
>
> -------------------------------------------
> Att. Edimar Manica
> Mestrando em Ciência da Computação pela UFRGS
> Área: Banco de dados
> Orientadora: Renata Galante
> Currículo: http://lattes.cnpq.br/7497320738069454
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Exist-open mailing list
> Exist-open@...
> https://lists.sourceforge.net/lists/listinfo/exist-open
>
>



--
Adam Retter

eXist Developer
{ United Kingdom }
adam@...
irc://irc.freenode.net/existdb

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Break loop in XQuery

by Wolfgang Meier-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You cannot break out of a for loop. You are trying to write your query
in procedural style, whereas XQuery is a functional language. To
achieve what you want, use a recursive function.

> Also the xquery-talk mailing list may be a better place to ask such questions...

I think beginner's questions are better asked on the eXist mailinglist
(assuming you are using eXist).

Wolfgang

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Break loop in XQuery

by Wolfgang Meier-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> You cannot break out of a for loop. You are trying to write your query
> in procedural style, whereas XQuery is a functional language. To
> achieve what you want, use a recursive function.

For example (quick hack):

declare function local:process($seq) {
  if (exists($seq) and $seq[1] != 0) then
    ($seq[1], local:process(subsequence($seq, 2)))
  else
    ()
};

local:process((1, 2, 5, 3, 0, 6, 3, 5))

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

Re: Break loop in XQuery

by Edimar Manica :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This solves my problem

Thank you very much

-------------------------------------------
Att. Edimar Manica
Mestrando em Ciência da Computação pela UFRGS
Área: Banco de dados
Orientadora: Renata Galante
Currículo: http://lattes.cnpq.br/7497320738069454


2009/11/11 Wolfgang Meier <wolfgang@...>
> You cannot break out of a for loop. You are trying to write your query
> in procedural style, whereas XQuery is a functional language. To
> achieve what you want, use a recursive function.

For example (quick hack):

declare function local:process($seq) {
 if (exists($seq) and $seq[1] != 0) then
   ($seq[1], local:process(subsequence($seq, 2)))
 else
   ()
};

local:process((1, 2, 5, 3, 0, 6, 3, 5))


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open