This document defines a general set of functions grouped together under “zorba-util” namespace, since the same functions are defined by Zorba. The only major difference is that Zorba uses Tidy as HTML cleaner, whereas MXQuery uses Tagsoup. As a result, MXQuery does not support the additional tidy options.
In order to use util functions, the module "http://www.zorba-xquery.com/zorba/util-functions" has to be included at the beginning of a query. For example

import module namespace zorba-util = "http://www.zorba-xquery.com/zorba/util-functions";

Functions for HTML Cleaning

declare function tidy($str as xs:string) as item()
Summary: Assuming $str contains a “dirty” HTML the function will return an item containing a valid XHTML version of the $str.
Example:

 import module namespace
  fn-zorba-util="http://www.zorba-xquery.com/zorba/util-functions";
  fn:string(fn-zorba-util:tidy('<title>Foo&kl;/title%gt;<p>Foo!'))

declare function tdoc($uri as xs:string?) as document-node()?

Summary: This function if very similar to fn:doc from XQuery 1.0 and XPath 2.0 Functions and Operators. The only difference is that prior to parsing the document identified by $uri , tdoc transforms the document into a valid XHTML document with the help of TagSoup.

import module namespace
  fn-zorba-util="http://www.zorba-xquery.com/zorba/util-functions";
  fn-zorba-util:tdoc('http://tidy.sourceforge.net/libintro.html')

Functions for UUIDs

declare function uuid() as xs:string

Functions for Random Numbers

declare function random() as xs:integer
declare function random($seed as xs:integer) as xs:integer

Summary: Function for generating a random integer.

$seed can be used to set the starting point of the std::rand sequence. If random is called whithin a loop but diffrent numbers are expected as a result this parameter should be set

Examples:

 import module namespace zu = http://www.zorba-xquery.com/zorba/util-functions";
  for $i in (1 to 10)
    return zu:random($i)

If no seed is provided as an argument the same number will be generated every time (when called within the same query)

import module namespace zu = "http://www.zorba-xquery.com/zorba/util-functions";
   for $i in (1 to 10)
    return zu:random()