[XML4Lib] Alphabetical Listing
Winona Salesky
wsalesky at gmail.com
Fri Oct 19 09:49:12 EDT 2007
Hi Nicole,
I have an xquery that does this...I use it for browsing our EAD collection [
http://cdi.uvm.edu/findingaids/browseEAD.xql?cat=A]
Essentially you just need to create an external variable to pass the letter
(A, B, etc) to the list, and also specify the default value, "A" if no value
is passed in the url. Then just use the starts-with function to pull the
list you want.
declare function local:browseCat($cat){
if(exists($cat) and $cat != '') then
if($cat = 'all') then
starts-with(archdesc/did/origination[@label = 'Creator'][1], '')
else
starts-with(archdesc/did/origination[@label = 'Creator'][1], $cat)
else
starts-with(archdesc/did/origination[@label = 'Creator'][1], 'A')
};
let $cat := request:request-parameter("cat", "")
let $xsl := doc('/db/stylesheets/browseEAD.xsl')
let $results :=
<html>
{
for $ead in
collection('/db/ead')/ead[local:browseCat($cat)]
let $title := $ead/archdesc/did/unittitle[1]
let $creator := $ead/archdesc/did/origination[@label =
'Creator'][1]
let $id := normalize-space($ead/eadheader/eadid)
let $abstract := $ead/archdesc/did/abstract[1]
let $date := $ead/archdesc/did/unitdate[1]
let $extent := $ead/archdesc/did/physdesc[1]
order by $creator ascending
return
<results date="{string($date)}" id="{string($id)}"
creator="{string($creator)}" class="{substring($creator, 1, 1)}"
title="{string($title)}"
extent="{string($extent)}">{string($abstract)}</results>
}
</html>
return xslt:transform($results, $xsl, () )
Hope that helps.
-Winona
On 10/19/07, Engard, Nicole <nicole.engard at ptsem.edu> 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 J
>
>
>
> 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
>
>
>
> _______________________________________________
> XML4Lib mailing list
> XML4Lib at webjunction.org
> http://lists.webjunction.org/mailman/listinfo/xml4lib
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.webjunction.org/wjlists/xml4lib/attachments/20071019/76f6c3f2/attachment.htm
More information about the XML4Lib
mailing list