Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

XQuery/Wikibook index page

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

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 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> XQuery Index XForms Index XRX