(: : Copyright (c)2005 Elsevier, Inc. : : Licensed under the Apache License, Version 2.0 (the "License"); : you may not use this file except in compliance with the License. : You may obtain a copy of the License at : : http://www.apache.org/licenses/LICENSE-2.0 : : Unless required by applicable law or agreed to in writing, software : distributed under the License is distributed on an "AS IS" BASIS, : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. : See the License for the specific language governing permissions and : limitations under the License. : : The use of the Apache License does not indicate that this project is : affiliated with the Apache Software Foundation. :) (:~ : This module provides the functions that control the Web presentation : of xqDoc. The logic contained in this module is not specific to any : XQuery implementation and is written to the May 2003 XQuery working : draft specification. : : It should also be noted that these functions not only support the : real-time presentation of the xqDoc information but are also used : for the static offline presentation mode as well. The static offline : presentation mode has advantages because access to a native XML : database is not needed when viewing the xqDoc information ... it is : only needed when generating the offline materials. : : @author Darin McBeath : @since February 27, 2005 : @version 1.1 :) module "xqdoc/xqdoc-display" declare namespace display="xqdoc/xqdoc-display" declare namespace xq="http://www.xqdoc.org/1.0" (:~ : This variable defines the name for the xqDoc collection. : The xqDoc XML for all modules should be stored into the : XML database with this collection value. :) define variable $display:XQDOC_COLLECTION as xs:string {"xqdoc" } (:~ : This variable contains the list of URIs for all of the modules : available to xqDoc for presentation. Each module should be identified by : a unique URI in the XML databse. :) define variable $display:XQDOC_URIS as xs:string* { for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc order by $x/xq:module/xq:uri return fn:base-uri($x) } (:~ : Construct the welcome banner for the xqDoc home page. : : @param $local indicates whether to build static HTML link for offline : viewing or dynamic linke for real-time viewing. : @return HTML. :) define function display:print-intro($local as xs:boolean) as element()+ { (

Welcome to xqDoc

,

This site presents documentation and cross-referencing information for both XQuery library and main modules that have been converted into xqDoc XML. Visit xqdoc.org to find the latest developments for this XQuery open source tool.

) } (:~ : Construct the welcome banner for the xqDoc module page. : : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-module-intro($local as xs:boolean) as element() { display:build-link("default", $local, (), ()) } (:~ : Construct the list of modules available to xqDoc for presentation. : The list of modules is availalbe on the xqDoc home page. : : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-modules($local as xs:boolean) as element()+ { (
{ if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:module[@type="library"])) then (

Library Modules

,
,
, for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc[xq:module/@type="library"] order by $x/xq:module/xq:uri return ( display:build-link("get-module", $local, (fn:base-uri($x)), display:decode-uri(fn:string($x/xq:module/xq:uri))),
) ) else () } { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:module[@type="main"])) then (

Main Modules

,
,
, for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc[xq:module/@type="main"] order by $x/xq:module/xq:uri return ( display:build-link("get-module", $local, (fn:base-uri($x)), display:decode-uri(xs:string($x/xq:module/xq:uri))),
) ) else () }
) } (:~ : The controller for constructing the xqDoc HTML information for : the specified module. The following information for : each module will be generated. : : : @param $uri the URI for the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-module-control($uri as xs:string, $local as xs:boolean) as item()+ { ( display:print-module($uri, $local), display:print-variables($uri, $local), " ", display:print-imports($uri, $local), " ", display:print-method-summary($uri), " ", display:print-method-detail($uri, $local), display:print-footer($uri) ) } (:~ : Construct the high-level xqDoc HTML for the module. : This is essentially any introductory xqDoc comments that might : be associated with the module. : : @param $uri the URI for the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-module($uri as xs:string, $local as xs:boolean) as element()* { (

Module URI

,

{ display:decode-uri(xs:string(fn:doc($uri)/xq:xqdoc/xq:module/xq:uri)) }

, if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:body)) then display:build-link("get-code", $local, $uri, ()) else (), if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:description) or fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:author) or fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:version) or fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:since) or fn:exists(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:see)) then (

Module Description

, display:print-comment(fn:doc($uri)/xq:xqdoc/xq:module/xq:comment/xq:description, (), $local), ) else () ) } (:~ : Construct the high-level xqDoc HTML for any global variables : declared in the module. In addition, cross-reference : links will be included for the following: : : @param $uri the URI for the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-variables($uri as xs:string, $local as xs:boolean) as element()* { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable)) then (

Variables

,
{ for $v in fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable return
  • { fn:concat("$", xs:string($v/xq:uri)) }
  • { $v/xq:comment/xq:description/node() }
    { display:print-comment($v/xq:comment/xq:since, "Since:", $local) } { display:print-comment($v/xq:comment/xq:see, "See:", $local) }
{ display:print-internal-variable-references($v, $local) } { display:print-external-variable-references($v, $local) }
}
) else () } (:~ : Construct the high-level xqDoc HTML for any modules : imported by the module. : : @param $uri the URI for the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-imports($uri as xs:string, $local as xs:boolean) as element()* { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:imports/xq:import)) then (

Imported Modules

,
{ for $v in fn:doc($uri)/xq:xqdoc/xq:imports/xq:import return
  • { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:module[xq:uri = $v/xq:uri])) then display:build-link("get-module", $local, fn:base-uri(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:module[xq:uri = $v/xq:uri]), display:decode-uri(xs:string($v/xq:uri))) else display:decode-uri(xs:string($v/xq:uri)) }
  • {$v/xq:comment/xq:description/node() }
    { display:print-comment($v/xq:comment/xq:since, "Since:", $local) } { display:print-comment($v/xq:comment/xq:see, "See:", $local) }
}
) else () } (:~ : Construct the xqDoc HTML method summary for each function defined : in the module. The method summary will contain the function : signature and the first sentence of any xqDoc comments associated : with the function. : : @param $uri the URI for the module : @return HTML. :) define function display:print-method-summary($uri as xs:string) as element()* { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function)) then (

Function Summary

,
{ for $f in fn:doc($uri)/xq:xqdoc/xq:functions/xq:function order by fn:normalize-space(xs:string($f/xq:name)) ascending return }
) else () } (:~ : Construct the xqDoc HTML method detail for each function defined : in the module. The method detail will contain the function : signature and all xqDoc comments associated with the function. In : addition, cross-reference links will be included for the following: : : : @param $uri the URI for the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML. :) define function display:print-method-detail($uri as xs:string, $local as xs:boolean) as item()* { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function)) then (

Function Detail

,
{ for $f in fn:doc($uri)/xq:xqdoc/xq:functions/xq:function order by fn:normalize-space(xs:string($f/xq:name)) ascending return (
{fn:normalize-space(xs:string($f/xq:name))}
  • { if (fn:exists($f/xq:body)) then display:build-link("get-code", $local, ($uri,fn:normalize-space(xs:string($f/xq:name))), fn:normalize-space(xs:string($f/xq:name))) else () }
  • { display:print-signature($f/xq:signature, fn:false()) }
{display:print-detail-comment($f/xq:comment/xq:description, (), $local)}
    { (display:print-detail-comment($f/xq:comment/xq:param, "Parameters:", $local), display:print-detail-comment($f/xq:comment/xq:return, "Return:", $local), display:print-detail-comment($f/xq:comment/xq:error, "Errors:", $local), display:print-detail-comment($f/xq:comment/xq:since, "Since:", $local), display:print-detail-comment($f/xq:comment/xq:see, "See:", $local), display:print-detail-comment($f/xq:comment/xq:deprecated, "Deprecated:", $local) ) }
{ display:print-external-functions-invoked($f, $local), display:print-external-functions-invoked-by($f, $local), display:print-internal-functions-invoked($f, $local), display:print-internal-functions-invoked-by($f, $local), display:print-internal-variables-referenced($f, $local), display:print-external-variables-referenced($f, $local) }
, " ") }
, " ") else () } (:~ : Construct the xqDoc HTML for the function signature. : : @param $sigs the signatures associated with the current function. Although only one : signature is allowed for user-defined functions, more than one signature : is required to support other 'modules' such as XPath F & O. : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return String containing the marked up function signature. :) define function display:print-signature($sigs as xs:string*, $local as xs:boolean) as item()* { for $sig at $cnt in $sigs return (let $params := fn:substring-after($sig, "(") let $tokens := fn:tokenize($params, ",") let $count := fn:count($tokens) return (if ($cnt > 1) then ("OR",
,
) else (), for $token at $index in $tokens return (if ($index = 1) then xs:string("(") else (), if ($index = 1) then fn:normalize-space($token) else (" ", fn:normalize-space($token)), if ($index < $count) then xs:string(",") else (),
)),
) } (:~ : Construct the xqDoc HTML for the specified xqDoc comment. The following : xqDoc comment values are supported. : : : @param $comment the xqDoc comment element associated with a function : @param $name the xqDoc comment name to process (i.e. author, version, etc.) : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-comment($comment as element()*, $name as xs:string?, $local as xs:boolean) as element()* { if (fn:exists($comment)) then for $i in $comment return if (fn:not(fn:exists($name))) then

{$i/node()}

else if ($name = "See:") then
  • {fn:concat($name, " ")}{display:print-comment-see($i, $local)}
  • else
  • {fn:concat($name, " ")}{$i/node()}
  • else () } (:~ : Construct the detailed xqDoc HTML for the specified xqDoc comment. : Detailed essentially implies the xqDoc comments for the method detail. The following : xqDoc comment values are supported. : : : @param $comment the xqDoc comment element associated with a function : @param $name the xqDoc comment name to process (i.e. author, version, etc.) : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-detail-comment($comment as element()*, $name as xs:string?, $local as xs:boolean) as element()* { if (fn:exists($comment)) then if (fn:exists($name)) then (
  • {$name}
  • , ) else

    {$comment/node()}

    else () } (:~ : Construct the xqDoc HTML for the specified xqDoc param comment element. : : @param $entry the xqDoc param comment element associated with a function : @return HTML :) define function display:print-comment-param($entry as element()) as item()* { let $tmp := xs:string(($entry/node())[1]) let $bef := fn:substring-before(fn:normalize-space($tmp), " ") let $aft := fn:substring-after(fn:normalize-space($tmp), " ") return (if (fn:string-length($bef) > 0) then fn:concat($bef, " - ", $aft) else $tmp, (for $x at $y in $entry/node() return if ($y > 1) then (" ", $x, " ") else ()),
    ) } (:~ : Construct the xqDoc HTML for the specified xqDoc see comment element. : If the comment is a URI that exists for a module contained within : xqDoc, build a link to this module (and optionally method or variable : name. If the comment is a 'http://' URL, then build a link to the URL. If the : comment is simply text, return the text. With version 1.1, it is now also : possible to specify the visible display name for the link. This is accomplished : by specifying an option second semi-colon followed by the link name. So, the : format for the parameter would be as follows: :

    : : a mandatory uri (or text) ';' an optional variable or method name ';' an optional link name : : @param $entry the xqDoc param comment element associated with a function : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-comment-see($entry as element(), $local as xs:boolean) as item()* { let $tmp := fn:normalize-space(xs:string($entry)) let $tokens := fn:tokenize($tmp, ";") return if (fn:count($tokens) = 1) then if (fn:not(fn:contains($tokens,"#")) and fn:exists(fn:doc($tokens))) then display:build-link("get-module", $local, $tokens, $tmp) else if (fn:starts-with($tokens, "http")) then {$tokens} else $entry/node() else if (fn:count($tokens) = 2) then if (fn:not(fn:contains($tokens[1],"#")) and fn:exists(fn:doc($tokens[1])//xq:functions/xq:function[xq:name = fn:normalize-space($tokens[2])])) then display:build-link("get-module", $local, $tokens, $tmp) else $entry/node() else if (fn:count($tokens) = 3) then if (fn:string-length($tokens[2]) = 0 and fn:not(fn:contains($tokens[1],"#")) and fn:exists(fn:doc($tokens[1]))) then display:build-link("get-module", $local, $tokens, $tokens[3]) else if (fn:string-length($tokens[2]) = 0 and fn:starts-with($tokens[1], "http")) then {$tokens[3]} else if (fn:string-length($tokens[2]) > 0 and fn:not(fn:contains($tokens[1],"#")) and fn:exists(fn:doc($tokens[1])//xq:functions/xq:function[xq:name = fn:normalize-space($tokens[2])])) then display:build-link("get-module", $local, $tokens, $tokens[3]) else $entry/node() else $entry/node() } (:~ : Construct the information to identify those functions (contained in : other modules) that are used by the current function. If that : module exists in xqDoc, construct a link to the module and function. : If that module does not exist in xqDoc, simply identify the : module and function name. : : @param $function the current function : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-external-functions-invoked($function as element(), $local as xs:boolean) as element()* { if (fn:exists($function/xq:invoked[xq:uri != display:module-uri($function)])) then

    External Functions that are used by this Function
    { let $uris := for $x in fn:distinct-values($function/xq:invoked/xq:uri) where $x != display:module-uri($function) order by xs:string($x) return xs:string($x) for $uri in $uris let $names := for $y in $function/xq:invoked[xq:uri=$uri] order by xs:string($y/xq:name) return xs:string($y/xq:name) for $name at $i in $names return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, $name), $name) } {$name}
    { display:build-link("get-module", $local, ($uri, $name), $name) } {$name}
    else () } (:~ : Construct the information to identify those functions (contained in : other modules) that use the current function. If that : module exists in xqDoc, construct a link to the module and function. : If that module does not exist in xqDoc, simply identify the : module and function name. : : @param $function the current function : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-external-functions-invoked-by($function as element(), $local as xs:boolean) as element()* { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:invoked[display:module-uri(.) != display:module-uri($function) and xq:uri=display:module-uri($function) and xq:name=xs:string($function/xq:name)])) then
    External Functions that invoke this Function
    { let $list := for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:invoked[xq:uri=display:module-uri($function) and xq:name=xs:string($function/xq:name)] return $x let $uris := fn:distinct-values(for $y in $list where display:module-uri($y) != display:module-uri($function) order by display:module-uri($y) return display:module-uri($y)) for $uri in $uris let $entries := for $entry in $list where display:module-uri($entry)=$uri order by $entry/../xq:name return $entry for $entry at $i in $entries return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    else () } (:~ : Construct the information to identify those functions (contained in the module : for the current function) that are used by the current function. : Construct a link to the module and function. : : @param $function the current function : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-internal-functions-invoked($function as element(), $local as xs:boolean) as element()* { if (fn:exists($function/xq:invoked[xq:uri = display:module-uri($function)])) then
    Internal Functions used by this Function
    { let $uris := for $x in fn:distinct-values($function/xq:invoked/xq:uri) where $x = display:module-uri($function) order by xs:string($x) return xs:string($x) for $uri in $uris let $names := for $y in $function/xq:invoked[xq:uri=$uri] order by xs:string($y/xq:name) return xs:string($y/xq:name) for $name at $i in $names return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, $name), $name) } {$name}
    { display:build-link("get-module", $local, ($uri, $name), $name) } {$name}
    else () } (:~ : Construct the information to identify those functions (contained in the module : for the current function) that use the current function. : Construct a link to the module and function. : : @param $function the current function : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-internal-functions-invoked-by($function as element(), $local as xs:boolean) as element()* { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:invoked[display:module-uri(.) = display:module-uri($function) and xq:uri=display:module-uri($function) and xq:name=xs:string($function/xq:name)])) then
    Internal Functions that invoke this Function
    { let $list := for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:invoked[xq:uri=display:module-uri($function) and xq:name=xs:string($function/xq:name)] return $x let $uris := fn:distinct-values(for $y in $list where display:module-uri($y) = display:module-uri($function) order by display:module-uri($y) return display:module-uri($y)) for $uri in $uris let $entries := for $entry in $list where display:module-uri($entry)=$uri order by $entry/../xq:name return $entry for $entry at $i in $entries return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    else () } (:~ : Construct the information to identify those functions (defined in other modules : from the current variable) that used the current variable. If that : module exists in xqDoc, construct a link to the module and function. : If that module does not exist in xqDoc, simply identify the : module and function name. : : @param $variable the current variable : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-external-variable-references($variable as element(), $local as xs:boolean) as element()* { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:ref-variable[display:module-uri(.) != display:module-uri($variable) and xq:uri=display:module-uri($variable) and xq:name=xs:string($variable/xq:uri)])) then
    External Functions that reference this Variable
    { let $list := for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:ref-variable[xq:uri=display:module-uri($variable) and xq:name=xs:string($variable/xq:uri)] return $x let $uris := fn:distinct-values(for $y in $list where display:module-uri($y) != display:module-uri($variable) order by display:module-uri($y) return display:module-uri($y)) for $uri in $uris let $entries := for $entry in $list where display:module-uri($entry)=$uri order by $entry/../xq:name return $entry for $entry at $i in $entries return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    else () } (:~ : Construct the information to identify those functions (defined in the module : for the current variable) that use the current variable. : Construct a link to the module and function. : : @param $variable the current variable : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-internal-variable-references($variable as element(), $local as xs:boolean) as element()* { if (fn:exists(fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:ref-variable[display:module-uri(.) = display:module-uri($variable) and xq:uri=display:module-uri($variable) and xq:name=xs:string($variable/xq:uri)])) then
    Internal Functions that reference this Variable
    { let $list := for $x in fn:collection($display:XQDOC_COLLECTION)/xq:xqdoc/xq:functions/xq:function/xq:ref-variable[xq:uri=display:module-uri($variable) and xq:name=xs:string($variable/xq:uri)] return $x let $uris := fn:distinct-values(for $y in $list where display:module-uri($y) = display:module-uri($variable) order by display:module-uri($y) return display:module-uri($y)) for $uri in $uris let $entries := for $entry in $list where display:module-uri($entry)=$uri order by $entry/../xq:name return $entry for $entry at $i in $entries return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:functions/xq:function[xq:name = $entry/../xq:name])) then else } }
    Module URI Function Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    { display:build-link("get-module", $local, ($uri, xs:string($entry/../xq:name)), xs:string($entry/../xq:name)) } {xs:string($entry/../xq:name)}
    else () } (:~ : Construct the information to identify those functions (defined in other modules : from the current variable) that use the current variable. If that : module exists in xqDoc, construct a link to the module and function. : If that module does not exist in xqDoc, simply identify the : module and function name. : : @param $variable the current variable : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-external-variables-referenced($variable as element(), $local as xs:boolean) as element()* { if (fn:exists($variable/xq:ref-variable[xq:uri != display:module-uri($variable)])) then
    External Variables used by this Function
    { let $uris := for $x in fn:distinct-values($variable/xq:ref-variable/xq:uri) where $x != display:module-uri($variable) order by xs:string($x) return xs:string($x) for $uri in $uris let $names := for $y in $variable/xq:ref-variable[xq:uri=$uri] order by xs:string($y/xq:name) return xs:string($y/xq:name) for $name at $i in $names return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable[xq:uri = $name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable[xq:uri = $name])) then else } }
    Module URI Variable Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, fn:concat("$",$name)), fn:concat("$",$name)) } {fn:concat("$",$name)}
    { display:build-link("get-module", $local, ($uri, fn:concat("$",$name)), fn:concat("$",$name)) } {fn:concat("$",$name)}
    else () } (:~ : Construct the information to identify those functions (defined in the module : for the current variable) that use the current variable. : Construct a link to the module and function. : : @param $variable the current variable : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:print-internal-variables-referenced($variable as element(), $local as xs:boolean) as element()* { if (fn:exists($variable/xq:ref-variable[xq:uri = display:module-uri($variable)])) then
    Internal Variables used by this Function
    { let $uris := for $x in fn:distinct-values($variable/xq:ref-variable/xq:uri) where $x = display:module-uri($variable) order by xs:string($x) return xs:string($x) for $uri in $uris let $names := for $y in $variable/xq:ref-variable[xq:uri=$uri] order by xs:string($y/xq:name) return xs:string($y/xq:name) for $name at $i in $names return if ($i = 1) then (, { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable[xq:uri = $name])) then else } ) else { if (fn:exists(fn:doc($uri)/xq:xqdoc/xq:variables/xq:variable[xq:uri = $name])) then else } }
    Module URI Variable Name
    {" "}{" "}
    {display:decode-uri($uri)} { display:build-link("get-module", $local, ($uri, fn:concat("$",$name)), fn:concat("$",$name)) } {fn:concat("$",$name)}
    { display:build-link("get-module", $local, ($uri, fn:concat("$",$name)), fn:concat("$",$name)) } {fn:concat("$",$name)}
    else () } (:~ : Decode the uri. This routine is needed for some XML databases that : have problems with specific characters contained in a document URI. : This routine makes the URI more human readable ... by removing the : encoding. Currently, the only character encoded is a "/". Other : characters could easily be added. However, they would also need to : be specified in the xqDoc conversion package (XQDocContext). : : @param $uri the string to be decoded : @return the decoded string :) define function display:decode-uri($uri as xs:string) as xs:string { fn:replace($uri, "~2F", "/") } (:~ : Find the module uri for the associated element. This routine is needed : since we can't rely soley on base-uri(). Instead, the xqDoc XML URI is : contained in the XML of the document (the xqDoc module section). : : @param $e the element (i.e. function or variable) that we want to find the module uri : @return the module URI associated with the element :) define function display:module-uri($e as element()) as xs:string { xs:string($e/ancestor::xq:xqdoc/xq:module/xq:uri) } (:~ : Construct the fotter information for the current module. : The footer will contain the version of the xqDoc conversion program : used to generate the xqDoc XML stored in the XML database and the : time when the XML was created. If the xqDoc conversion program was not : used (i.e. XPath F & O) then this information will be marked as N/A. : : @param $uri the current module uri : @return HTML :) define function display:print-footer($uri as xs:string) as element()* {
    Created by xqDoc version {xs:string(fn:doc($uri)/xq:xqdoc/xq:control/xq:version) } on {xs:string(fn:doc($uri)/xq:xqdoc/xq:control/xq:date) }
    } (:~ : Construct the HTML for the xqDoc home page. This will include the welcome : text and the list of modules available in xqDoc. : : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:get-default-html($local as xs:boolean) as element() { xqDoc -- Module List { display:get-stylesheet() } { display:print-intro($local) } { display:print-modules($local) } } (:~ : Construct the HTML for a xqDoc module page. : : @param $module the module uri : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML :) define function display:get-module-html($module as xs:string, $local as xs:boolean) as element() { xqDoc -- Module { display:get-stylesheet() } { display:print-module-intro($local) } { display:print-module-control($module, $local) } } (:~ : Construct a link. Based on the parameters, the link will be built : for the static (off-line viewing mode of xqDoc) or the dynamic viewing : mode of xqDoc. The parameters will also indicate which link to construct, : supply the appropriate paramters for the link, and assign a name for the link. : : @param $type the type of link to construct. The link can be for the xqDoc home : page, the module page for a particular module, or for the : XQuery code for a specific function. : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @param $parms the parameters associated with the link $type : @param $name the name to assign for the link : @return HTML :) define function display:build-link($type as xs:string, $local as xs:boolean, $parms as xs:string*, $name as xs:string?) as element()? { if ($type = "default") then if ($local = fn:true()) then

    xqDoc Home

    else xqDoc Home else if ($type = "get-module") then if ($local = fn:true()) then { $name } else { $name } else if ($type = "get-code") then if ($local = fn:true()) then if (fn:count($parms) > 1) then view code else view code else if (fn:count($parms) > 1) then view code else view code else () } (:~ : Construct a list of module uris contained in xqDoc. : : @return List of module uris contained in xqDoc :) define function display:get-module-uris() as xs:string* { $display:XQDOC_URIS } (:~ : Construct a list of function names defined in the current module. : : @param $module the uri for the current module : @return List of function names defined in the current module :) define function display:get-function-names($module as xs:string) as xs:string* { for $function in fn:doc($module)/xq:xqdoc/xq:functions/xq:function return if (fn:exists($function/xq:body)) then fn:normalize-space(xs:string($function/xq:name)) else () } (:~ : Construct the HTML that will contain the XQuery code for the function : in the current module (or the entire module). The code will be : presented via a Javascript popup Window from the module. The lack : of a $name parameter indicates to construct the HTML for entire module. : : : @param $module the uri associated with the current module : @param $name the name associated with the current function contained in the module : @param $local indicates whether to build static HTML link for offline : viewing or dynamic links for real-time viewing. : @return HTML ... the XQuery code for the function :) define function display:get-code-html($module as xs:string, $name as xs:string?, $local as xs:boolean) as element() { xqDoc -- Code Sample
    {
          if (fn:empty($name)) then
            let $body := fn:doc($module)/xq:xqdoc/xq:module
            return    
                if (fn:exists($body/*:body[@xml:space])) then
                  display:print-preserve-newlines(xs:string($body/*:body[@xml:space])) 
                else
                  ()
          else
            let $body := fn:doc($module)/xq:xqdoc/xq:functions/xq:function[xq:name = $name]   
            return      
              display:print-preserve-newlines(xs:string($body/*:body[@xml:space])) 
        }
        
    } (:~ : Modify the markup (i.e. newlines) associated with an XQuery function so that : it presents cleanly in HTML. : : @param $strin the code associated with an XQuery function : @return the presentation friendly version of the code :) define function display:print-preserve-newlines($strin as xs:string?) as item()* { for $i in fn:tokenize($strin, "\n") return ($i,
    ) } (:~ : Get the xqDoc presentation stylesheet. This is embedded into : the returned XHTML for all of the presentation pages. It is : embedded into pages (instead of referencing a link) to keep : things simple for the off-line viewing mode. : : @return the stylesheet :) define function display:get-stylesheet() as element() { }