XQuery/Wikibook index page

      Motivation

      You want to create an index of pages in a Wikibook.

      Method

      Fetch the Category page for the book and re-format based on the initial letter of the page, hence skipping the category level.


      Simple Index page

      This index page is based on the names of pages within the book. Its starting point is the Category with the same name as the book, into which all pages need to be put.

      declare namespace h ="http://www.w3.org/1999/xhtml";
      declare option exist:serialize "method=xhtml media-type=text/html";
       
      let $book:= request:get-parameter("book",())
      let $base := "http://en.wikibooks.org"
      let $indexPage :=doc(concat($base,"/wiki/Category:",$book))
      let $pages := $indexPage//h:div[@id="mw-pages"]//h:li
       
      return
       
      <html>
      <h1>Index of {$book}</h1>
      {
      for $letter in distinct-values($pages/substring(substring-after(.,'/'),1,1))[string-length(.) = 1]
      return
      <div>
      <h3>{$letter}</h3>
      <ul>
      {for $page in $pages[starts-with(substring-after(.,'/'),$letter)]
       
      let $url := concat($base,$page/h:a/@href)
       return
         <li> <a href="{$url}">{substring-after($page,'/')}</a>
         </li>
      }
      </ul>
      </div>
      }
      </html>
      

      XQuery Index

      XForms Index

      XRX

      Last modified on 6 November 2008, at 19:33