Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX - |
Contents
Index
![]() ![]() |
Part 1 The Basic for Developing Application | > Chapter 3 Data Search Methods | > 3.5 Sorting Search Results |
It is possible to perform a sort using the values of more than one element node or the value of the attribute nodes of those element nodes in an XML document. Commas are used to separate key specifications in the sort expression. The keys can be either a numeric or character string. Multiple keys make it possible to perform more sophisticated sorting operations. For example, XML documents can be sorted in ascending order using one element node and, if that element node is the same in more than one document, the documents can be further sorted in ascending order using a second element node.
Up to eight keys can be specified.
The explanation that follows assumes that Documents A, B, and C below exist:
Document A
<doc> <basic date="2006/03/03" expense="$76.50"> : </basic> : <detail> : <hotel>$96.00</hotel> : </detail> </doc> |
Document B
<doc> <basic date="2006/03/03" expense="$115.00"> : </basic> : <detail> : <hotel>$89.00</hotel> : </detail> </doc> |
Document C
<doc> <basic date="2006/03/10" expense="$76.50"> : </basic> : <detail> : <hotel>$140.90</hotel> : </detail> </doc> |
Example 1
Sort documents according to the trip date (date) and, if multiple documents contain the same trip date, then sort in descending order according to the accommodation costs (hotel):
/doc/basic/@date,val(/doc/detail/hotel/text()) DESCResult: Documents are returned in the order A, B, C.
Example 2
Sort documents according to the trip date (date) and, if multiple documents contain the same trip date, then sort in descending order according to the trip expenses (expense):
/doc/basic/@date,val(/doc/basic/@expense) DESCResult: Documents are returned in the order B, A, C.
Contents
Index
![]() ![]() |