Skip to content

Instantly share code, notes, and snippets.

Created July 1, 2010 18:05
Show Gist options
  • Save anonymous/460316 to your computer and use it in GitHub Desktop.
Save anonymous/460316 to your computer and use it in GitHub Desktop.
xquery version "1.0-ml";
declare default element namespace "http://www.w3.org/1999/xhtml";
(: This function takes the children of the node and passes them
back into the typeswitch function. :)
declare function local:passthru($x as node()) as node()*
{
for $z in $x/node() return local:dispatch($z)
};
(: This is the recursive typeswitch function :)
declare function local:dispatch($x as node()) as node()*
{
typeswitch ($x)
case text() return $x
case element (a) return local:passthru($x)
case element (title) return <h1>{local:passthru($x)}</h1>
case element (para) return <p>{local:passthru($x)}</p>
case element (sectionTitle) return <h2>{local:passthru($x)}</h2>
case element (numbered) return <ol>{local:passthru($x)}</ol>
case element (number) return <li>{local:passthru($x)}</li>
default return <tempnode>{local:passthru($x)}</tempnode>
};
let $x :=
<a>
<title>This is a Title</title>
<para>Some words are here.</para>
<sectionTitle>A Section</sectionTitle>
<para>This is a numbered list.</para>
<numbered>
<number>Install MarkLogic Server.</number>
<number>Load content.</number>
<number>Run very big and fast XQuery.</number>
</numbered>
</a>
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>MarkLogic Sample Code</title></head>
<body>{local:dispatch($x)}</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment