Re: eXist, XQuery & flowr - order results by element and limit number returned by positi

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: eXist, XQuery & flowr - order results by element and limit number returned by positi

Tanya Gray (Oxford)
hmmm.. I should have waited before posting.. anyway.. here is the XQuery I have now, to address requirement described previously, in case it is useful to someone else:

<result>
{
let $result :=
for $x in /*
order by $x/element-name
   return $x

for $y at $pos in $result
where ($pos gt 0) and ($pos lt 11)
return

<report>{$y/element-name}</report>
}

</result>





>>> [hidden email] 01/17/07 3:26 PM >>>
Hi,

I would like to present a summary of reports in an eXist database, ordered by a user-defined element, and then return only a subset of these reports (allow paging of results).

The number of reports that are queried exceeds 1500, and I would like to limit the XML transferred to the client. The following XQuery facilitates paging of results, however the $pos variable refers to the original position of the record in the collection and not the position of the record after it has been ordered by the selected element.

Is it is possible to retrieve the position of a record in a recordset, after it has been ordered, or is it necessary to select all records and then use the XSLT processor to retrieve records with the required position() value?

thank you for any info

Tanya


*********************************************************************************************

<xdb:query collection="/db/{$db-name}/reports" create-collection="true"
xmlns:xmldb="http://exist-db.org/xquery/xmldb"
xmlns:util="http://exist-db.org/xquery/util"
>

xquery version "1.0";
declare namespace fn='http://www.w3.org/2005/02/xpath-functions';
declare namespace xmldb='http://exist-db.org/xquery/xmldb';
<result >
{
 
for $x at $pos in /*
   <xsl:value-of select='$order-by'/>

    return
   
    if (($pos gt <xsl:value-of select='$from'/>)
        and ($pos lt <xsl:value-of select='$to'/>))  then
 
<report>  
   
<xsl:for-each select="doc('input:config-options')//report-summary/elements/element">
   
   { $x//*[name() = '<xsl:value-of select = "."/>']}
   
    </xsl:for-each>
   
<author>{doc('/db/<xsl:value-of select='$db-name'/>/user-accounts/Users.xml')//user[user-activity/report/@document-id= util:document-name($x)]/user-record/username/text()}</author>
<filename label='Filename'>{util:document-name($x)}</filename>
<date-modified>{xmldb:last-modified('/db/<xsl:value-of select='$db-name'/>/reports', util:document-name($x))}</date-modified>
    <position>{$pos}</position>    
       
</report>
   
    else
<null/>
 
}
</result>
</xdb:query>

****************************************************************************************





--
This message (and any attachments) is for the recipient only. NERC
is subject to the Freedom of Information Act 2000 and the contents
of this email and any reply you make may be disclosed by NERC unless
it is exempt from release under the Act. Any material supplied to
NERC may be stored in an electronic records management system.




--
This message (and any attachments) is for the recipient only. NERC
is subject to the Freedom of Information Act 2000 and the contents
of this email and any reply you make may be disclosed by NERC unless
it is exempt from release under the Act. Any material supplied to
NERC may be stored in an electronic records management system.




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws