[XML4Lib] Alphabetical Listing

David Sewell dsewell at virginia.edu
Fri Oct 19 10:14:06 EDT 2007


This is essentially a grouping task, and grouping is one area where
XQuery lacks the built-in power of XSLT. The commercial version of
Saxon, Saxon-SA, has an extension function for grouping:

 http://www.saxonica.com/documentation/extensions/functions/for-each-group.html

Saxon-SA is not cheap (£150 for the XQuery module), but I have found
that it provides many of the features and performance of a native XML
database product like MarkLogic Server, which costs well into 5 figures.
So by that standard it's a very good deal if you do a lot of this sort
of processing.

David S.

On Fri, 19 Oct 2007, Engard, Nicole wrote:

> Hi all,
>
>
>
> Just wondering if anyone has written an Xquery that will split a list up
> alphabetically.  In particular a list of authors/titles.  I want to put
> an A-Z list of links at the top of the page so people can see just the
> authors with names starting with B if they way - and so on.  I figured
> why re-invent the wheel if someone else has done it already :-)
>
>
>
> This is my list:
>
>
>
> define function display-authorlist($params as node()) as node() {
>
>   (: Display introductory text :)
> <span>
>     <h1>Alphabetical Listing of Authors</h1>
>     <ul>
>   {
>     (: Search creators and include total contributions :)
>     for $creators in fn:distinct-values(
>       for $creator in fn:collection()//dc:creator
>       let $uniformName
> :=fn:normalize-space(fn:replace($creator,",.*$",""))
>       order by fn:tokenize($uniformName, " ")[fn:last()]
>       return $uniformName)
>     let
> $count:=xdmp:estimate(/METS:mets/METS:dmdSec/METS:mdWrap/METS:xmlData/dc
> :creator[cts:contains(., $creators)])
>     where $count != 0
>     return <li><a href="default.xqy?terms={$creators}">{$creators}</a>
> ({$count})</li>
>   }
>   </ul>
> </span>
> }
>
>
>
> It's a bit insane right now without having some sort of division.
>
>
>
> Thanks,
>
> Nicole C. Engard
>
> Metadata Librarian
>
>
>
>

-- 
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 801079, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/


More information about the XML4Lib mailing list