Skip to content

Instantly share code, notes, and snippets.

@joewiz
Created April 7, 2012 19:33
Show Gist options
  • Save joewiz/2331558 to your computer and use it in GitHub Desktop.
Save joewiz/2331558 to your computer and use it in GitHub Desktop.
My XQuery snippets
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index>
<!-- Old full text index configuration. Deprecated. -->
<fulltext default="none" attributes="false"/>
<!-- New full text index based on Lucene -->
<lucene>
<text qname="SPEECH">
<ignore qname="SPEAKER"/>
</text>
<text qname="TITLE"/>
</lucene>
<!-- Range indexes -->
<create qname="title" type="xs:string"/>
<!-- N-gram indexes -->
<ngram qname="title"/>
</index>
</collection>
xquery version "1.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
xquery version "1.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare function local:render($node) {
typeswitch($node)
case text() return $node
case element(tei:div) return <div>{local:recurse($node)}</div>
case element(tei:p) return <p>{local:recurse($node)}</p>
default return local:recurse($node)
};
declare function local:recurse($node) {
for $child in $node/node()
return
local:render($child)
};
xquery version "1.0";
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
xquery version "1.0";
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
let $title := 'My Title'
let $content := <p>My Content</p>
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$title}</title>
</head>
<body>
<div>
<h1>{$title}</h1>
{$content}
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment