Right after the (American) Thanksgiving holiday and just before London Online, the world's best XQuery coders, Jason Hunter and Ryan Grimm, will be over in Royal London hosting an XQuery day. The event details are:
Code with the XQuery Experts
Friday, November 30, 2007
8:30 am PT - 5:00 pm
Olympia Grand Hall
London, England
Sign up for it here.
Jason and Ryan have been using XQuery (and MarkLogic Server) from the very start and it should be an excellent event to see firsthand why XQuery is THE application language for content applications.
What's more, you can bring your own XQuery chops and win an 8GB iPhone for the Best XQuery App at the event. There are some helpful tools in the Mark Logic code workshop to get you started and I expect full credit if something in my tutorial helps you win first place!
But you might want to 'enhance' this one: I asked Jason and Ryan for something neat from the amazing XQuery powered email discovery application they've built called MarkMail and they send me this very elegant FAQ generator.
The first cool thing is that it's a complete FAQ in a single complete XQuery - starting with the content and then the code to present it:
(: content as XHTML in a div - edited by MT to be a sample :)
let $content :=
<div id="content">
<a name="general"/>
<h1>GENERAL FAQ</h1><a name="quick"/>
<h2>Given 15 seconds, what should I know?</h2>
<ul><li>MarkMail lets you search 4,000,000+ emails across 500+ Apache mailing lists</li>
...</ul>
<a name="whatisit"/>
<h2>What is MarkMail?</h2>
<p>
MarkMail is a community-focused searchable message archive, accessible at <a
href="http://markmail.org">http://markmail.org</a>, developed and hosted by <a
href="http://www.marklogic.com">Mark Logic Corporation</a>.
...
</p>
...
<a name="techie"/><h1>TECHIE FAQ</h1>
<a name="whatshard"/>
<h2>What's hard about searching email?</h2>
<p>
Email doesn't work well in a relational model because there's too much free
text. It doesn't work well in a search engine either because there's too much ad hoc structure and hierarchy ... We've found email works naturally as XML.
...
</p>
<a name="store"/>
<h2>How do you store the emails?</h2>
<p>
Each email is stored an XML document inside MarkLogic Server.
...
</p>
...
</div>(: from this XHTML node we can generate the table of contents including a split between regular and techie FAQ
:)let $toc :=
<div class="toc">
<h1>Table of Contents</h1>
<ul>
{
for $head in $content/h2[. << $content/h1[. = "TECHIE FAQ"]]
let $name := $head/preceding::*[1][name(.) = "a"]/@name
return <li><a href="#{ $name }">{ string($head) }</a></li>
}
</ul>
<h3>Techie FAQ</h3>
<ul>
{
for $head in $content/h2[. >> $content/h1[. = "TECHIE FAQ"]]
let $name := $head/preceding::*[1][name(.) = "a"]/@name
return <li><a href="#{ $name }">{ string($head) }</a></li>
}
</ul>
</div>(: then we put it all together :)
let $body := (
<div id="docs">
{ $toc }
{ $content }
</div>,
<div style="clear: both"/>
)return
(: and output it :)
$body
I like that XQuery gives you a compete tool kit for content: even if you just have simple HTML you can do things like use the << and >> order comparison operators to pull out all of the <h2> elements that come before the Techie FAQ H1 and grab the <a> element right before the <h2> using the preceding axis.
And you're creating the output as you go - with an XHTML FAQ generated in less than 30 lines. To see the 'live' FAQ click here.
I hope you can make it out to the event at Olympia and can see first hand the many cool things you can do with XQuery, the right tool for the content application job.
Matt
Comments