Limit the number of results

Hello,

I have an XQuery which returns me all documents with a certain value in the name-element and sorts them by a date and time given in elements in the documents. Everything works fine, but now I want to limit the number of returned documents e.g. to 5.

How can I accomplish this?

Thanks in advance,
Jo Richter

e.g. in the followinig way:

(your XQuery here)[position() le 5]

Thanks for the very quick response.

I tried it with position() already, it doesn’t work. With the query:

declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction
declare namespace mtaresult=“http://www.mt.com/2005/xmlns/testresult
declare namespace xs=“XML Schema
for $myinput in input()/mtaresult:testresult
where $myinput/mtaresult:testplan/mtaresult:name=‘plan example’
return $myinput[position() le 5]

I still get all documents (I dropped the sort by expression for simplicity).

Why, do I do something wrong!?

Greetings,
Jo Richter

Yes, please add parantheses:

(declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction
declare namespace mtaresult=“http://www.mt.com/2005/xmlns/testresult
declare namespace xs=“XML Schema
for $myinput in input()/mtaresult:testresult
where $myinput/mtaresult:testplan/mtaresult:name=‘plan example’
return $myinput)[position() le 5]

Hello,

I was able to test it yesterday and it worked fine, so thank you very much for solving my problem!

Greetings,
Jo Richter