XQuery/Wikibook index page
< XQuery
Motivation
editYou want to create an index of pages in a Wikibook.
Method
editFetch 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
editThis 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 option exist:serialize "method=xhtml media-type=text/html";
let $book:= request:get-parameter("book",())
let $base := "http://en.wikibooks.org"
let $url := concat($base,"/wiki/Category:",$book)
let $indexPage :=httpclient:get(xs:anyURI($url),false(),())/httpclient:body
let $pages := $indexPage//div[@class="mw-category"]//li
return
<html>
<h1>Index of {$book} - <a href="{$url}">Wikibooks</a> </h1>
{
for $letter in distinct-values($pages/substring(substring-after(.,'/'),1,1))[string-length(.) = 1]
order by $letter
return
<div>
<h3>{$letter}</h3>
<ul>
{for $page in $pages[starts-with(substring-after(.,'/'),$letter)]
let $url := concat($base,$page/a/@href)
return
<li> <a href="{$url}">{substring-after($page,'/')}</a> </li>
}
</ul>
</div>
}
</html>