Figaro - The XML Database for the .NET Framework
Sorting the Result
See Also  Send Feedback
Figaro - the XML Database for the .NET Framework
Figaro - The XML Database for the .NET Framework

The 'O' in FLWOR stands for 'order by'. The previous XQuery expression did not contain explicit ordering instructions, and so the results were presented based on its order in the container. Over time, as the document set changes, the data will not maintain a constant order. Adding an explicit order by clause to the XQuery statement allows us to implement strict ordering:

Copy 
dbxml> query '<html><body>
    <ul>
        {
        for $part in 
            (collection("parts.dbxml")/part[@number > 100 and @number < 105]) 
        order by xs:decimal($part/@number) descending 
        return 
            <li>{$part/description/string()}</li>
        }
    </ul></body></html>'
1 objects returned for eager expression '<html><body>
    <ul>
        {
        for $part in 
            (collection("parts.dbxml")/part[@number > 100 and @number < 105]) 
        order by xs:decimal($part/@number) descending
        return 
            <li>{$part/description/string()}</li>
        }
    </ul></body></html>'

dbxml> print
<html><body><ul>
<li>Description of 104</li>
<li>Description of 103</li>
<li>Description of 102</li>
<li>Description of 101</li>
</ul></body></html>

The following shows the previous HTML as displayed in a web browser:

The parts are now ordered in descending order, as expected.

See Also

Other Resources

The dbxml Shell
Using FLWOR
Retrieving Documents Using XQuery
Performing Queries
Figaro - The XML Database for the .NET Framework

Copyright © 2008-2009 Endpoint Systems. All rights reserved.