XQuery/DocBook to HTML

Motivation
You would like to convert DocBook documents to HTML format.

Method
We will use an XQuery typewsitch transform that converts sample instance documents into an XQuery typeswitch module. To begin this process you can use any tool that generates an instance document from the XML Schema. You can then edit this document to include only the elements that you want to transform. You can then run this file through the tool to generate the typeswich XQuery module.

Dispatch Function
Our main dispatch function will have the following structure:

Note the following:
 * 1) the transform function takes a sequences of nodes as a parameter and the typeswitch function is retuned for each of the nodes.
 * 2) the transform returns a sequence of items
 * 3) the default action is to copy the node from the input to the output.  All nodes not in the case statement will be passed through without modification.  You can change this default behavior by changing the type returned by default.
 * 4) for each of the elements, a separate function "element function" is called.  If the elements are leaf elements they can just return the content of the leaf element.  If they are not leaf elements the MUST call the transform for each subbranch they contain.   By changing each function you can change what output is created by that element.  This structure keeps your transform modular and easy to maintain.
 * 5) the namespace for each element is the Docbook namespace (db is the prefix associated with the DocBook 5 URL http://docbook.org/ns/docbook
 * 6) all elements not in the case statement will be returned with an "u" for unknown element wrapper.  This makes them easy to spot when debugging.

Structure of the element functions
Each element function has a simple structure. For example the element might have the following structure:

This has the effect of converting all the  nodes into  nodes. Note that the input type is node and the return type is element. Also note that since elements contain other sub nodes (elements and text) they are all processed by the recursive call to db2html:transform($node/node).

Here is a full list of the functions for the above module.

Input
To invoke the transform you simply pass the root node of the DocBook document to the function:

Note that you MUST put the root element that you want to transform after the doc function. Without this the doc function returns a document node that will not match any of the document case statements.