Advertisement
Guest User

Cefn Hoile

a guest
Oct 21st, 2009
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 3.68 KB | None | 0 0
  1. xquery version "1.0";
  2.  
  3. import module namespace saxonb = "http://cefn.com/saxonb/" at "../lib/libout.xquery";
  4. declare namespace c="http://cefn.com/";
  5.  
  6. (:declare default element namespace "http://www.w3.org/1999/xhtml";:)
  7.  
  8. declare function c:href($node){
  9.     concat(encode-for-uri($node/@id), '.html')
  10. };
  11.  
  12. declare function c:wrapcontent($title as xs:string, $content){
  13.     <html>
  14.         <head><title>{$title}</title></head>
  15.         <body>
  16.             <h1>{$title}</h1>
  17.             {$content}
  18.         </body>
  19.     </html>
  20. };
  21.  
  22. declare function c:writeitem($item, $content){
  23.     saxonb:write-html(c:href($item),c:wrapcontent($item/@title,$content))    
  24. };
  25.  
  26. declare function c:writelink($item){
  27.     <a href="{c:href($item)}">{string($item/@title)}</a>
  28. };
  29.  
  30. declare function c:writelist($items){
  31.     <ul>
  32.         {for $item in $items order by $item/@title return <li><a href="{c:href($item)}">{string($item/@title)}</a></li>}
  33.     </ul>
  34. };
  35.  
  36. let $root := .,
  37.     $authors := $root/data/author,
  38.     $books := $root/data/book,
  39.     $collections := $root/data//collection,
  40.     $formats := for $formatname in distinct-values($collections/@type) return <format title="{$formatname}" id="{$formatname}"/>
  41. return (
  42.     saxonb:write-html('index.html',
  43.         c:wrapcontent('Librivox catalog improved',
  44.         <div>
  45.             <h1>Browse records...</h1>
  46.             <ul>
  47.                 <li><a href="author_list.html">by Author Name</a></li>
  48.                 <li><a href="book_list.html">by Book Title</a></li>
  49.                 <li><a href="format_list.html">by Download Format</a></li>
  50.             </ul>
  51.             <p/>
  52.             <p>If there are other shortcomings, errors or different list pages which would be useful, especially for
  53.             screenreaders, please <a href="http://cefn.com/blog/contact.html">contact me</a>.</p>
  54.             <p>I'm working on importing the descriptions for each title, but they are a mess of various standards
  55.             of HTML and throwing errors.</p>
  56.             <p><a href="http://cefn.com" >Cefn Hoile</a>, Mad Inventor</p>
  57.             <p>Snapshot at {current-dateTime()}</p>
  58.         </div>
  59.     )),
  60.     saxonb:write-html('author_list.html', c:wrapcontent('Author Name List',c:writelist($authors))),
  61.     saxonb:write-html('book_list.html', c:wrapcontent('Book Title List',
  62.         <ul>
  63.             {for $book in $books order by $book/@title return <li> {c:writelink($book)} [<i>{let $author := $authors[@id=$book/@authorid] return <a href="{c:href($author)}">{string($author/@id)}</a>}</i>] </li>}
  64.         </ul>
  65.     )),
  66.     saxonb:write-html('format_list.html', c:wrapcontent('Download Format List', c:writelist($formats))),
  67.     for $author in $authors return c:writeitem($author,
  68.         <ul>
  69.             {for $book in $books[@authorid=$author/@id] return <li><a href="{c:href($book)}">{string($book/@title)}</a></li>}
  70.         </ul>
  71.     ),
  72.     for $book in $books return c:writeitem($book, (
  73.             (: if($book/@description) then saxon:parse(string($book/@description)) else () ,:)
  74.             <ul>
  75.                 {for $collection in $book//collection return <li><a href="{$collection/@href}">{string($collection/@type)}</a></li>}
  76.             </ul>
  77.         )
  78.     ),    
  79.     for $format in $formats return c:writeitem($format,
  80.         <table>
  81.             {
  82.                 for $collection in $collections[@type=$format/@title]
  83.                 let $book := $collection/parent::book
  84.                 order by number($book/@downloads) descending
  85.                 return <tr><td width="30%">Downloads: {string($book/@downloads)}</td><td><a href="{$collection/@href}">{string($book/@title)}</a></td></tr>
  86.             }
  87.         </table>
  88.     )
  89. )
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement