load CSD documents into memory before processing

(:~
: This is the Care Services Discovery stored query registry
: @version 1.0
: @see https://github.com/openhie/openinfoman
:
:)
module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";

import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
declare namespace csd = "urn:ihe:iti:csd:2013";
declare default element  namespace   "urn:ihe:iti:csd:2013";

declare variable $csd_dm:document_manager := 'csd_docs.xml';

declare function csd_dm:blank_directory()
{
<CSD xmlns:csd="urn:ihe:iti:csd:2013" xmlns="urn:ihe:iti:csd:2013">
  <organizationDirectory/>
  <serviceDirectory/>
  <facilityDirectory/>
  <providerDirectory/>
</CSD>
};

declare  function csd_dm:document_source_exists($name) {
  let $source := csd_dm:document_source($name)
  return  if ($source) then (db:is-xml($csd_webconf:db,$source)) else false()

};

declare  function csd_dm:open_document($name) {
  if (csd_dm:document_source_exists($name)) then
    db:open($csd_webconf:db,csd_dm:document_source($name)) update{} (:stick it in main memory :)
  else
    csd_dm:blank_directory()
};

declare updating function csd_dm:add($doc,$name) {
  csd_dm:empty($name,$doc)
};

declare updating function csd_dm:delete($name) {
  db:delete($csd_webconf:db,csd_dm:document_source($name))
};

declare updating function csd_dm:empty($name) {
  csd_dm:empty($name,csd_dm:blank_directory())
};

declare updating function csd_dm:empty($name,$doc) {
  let $source := csd_dm:document_source($name)
  return
    if (csd_dm:document_source_exists($name)) then
      db:replace($csd_webconf:db,$source,$doc)
    else
      db:add($csd_webconf:db,$doc,$source)

};

declare function csd_dm:registered_documents() {
(:  db:list("service_directories/*") :)
  for $doc in db:list($csd_webconf:db,"service_directories")
  let $name := csd_dm:fn_base_name($doc,'.xml')
  return $name
};

declare function csd_dm:document_source($name) {
  concat("service_directories/",string($name),".xml")
};

declare function csd_dm:fn_base_name($file,$ext) {
  let $old_base_name := fn:function-lookup(xs:QName("file:base-name"), 2)
  return
    if (not(exists($old_base_name))) then
      fn:replace(fn:function-lookup(xs:QName("file:name"), 1)($file), fn:concat($ext, "$"), "")
    else
      $old_base_name($file,$ext)
};

(:~
: This is the Care Services Discovery stored query registry
: @version 1.0
: @see https://github.com/openhie/openinfoman
:
:)
module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";

import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
declare namespace csd = "urn:ihe:iti:csd:2013";
declare default element  namespace   "urn:ihe:iti:csd:2013";

declare variable $csd_dm:document_manager := 'csd_docs.xml';

declare function csd_dm:blank_directory()
{
<CSD xmlns:csd="urn:ihe:iti:csd:2013" xmlns="urn:ihe:iti:csd:2013">
  <organizationDirectory/>
  <serviceDirectory/>
  <facilityDirectory/>
  <providerDirectory/>
</CSD>
};

declare  function csd_dm:document_source_exists($name) {
  let $source := csd_dm:document_source($name)
  return  if ($source) then (db:is-xml($csd_webconf:db,$source)) else false()

};

declare  function csd_dm:open_document($name) {
  if (csd_dm:document_source_exists($name)) then
    db:open($csd_webconf:db,csd_dm:document_source($name))
  else
    csd_dm:blank_directory()
};

declare updating function csd_dm:add($doc,$name) {
  csd_dm:empty($name,$doc)
};

declare updating function csd_dm:delete($name) {
  db:delete($csd_webconf:db,csd_dm:document_source($name))
};

declare updating function csd_dm:empty($name) {
  csd_dm:empty($name,csd_dm:blank_directory())
};

declare updating function csd_dm:empty($name,$doc) {
  let $source := csd_dm:document_source($name)
  return
    if (csd_dm:document_source_exists($name)) then
      db:replace($csd_webconf:db,$source,$doc)
    else
      db:add($csd_webconf:db,$doc,$source)

};

declare function csd_dm:registered_documents() {
(:  db:list("service_directories/*") :)
  for $doc in db:list($csd_webconf:db,"service_directories")
  let $name := csd_dm:fn_base_name($doc,'.xml')
  return $name
};

declare function csd_dm:document_source($name) {
  concat("service_directories/",string($name),".xml")
};

declare function csd_dm:fn_base_name($file,$ext) {
  let $old_base_name := fn:function-lookup(xs:QName("file:base-name"), 2)
  return
    if (not(exists($old_base_name))) then
      fn:replace(fn:function-lookup(xs:QName("file:name"), 1)($file), fn:concat($ext, "$"), "")
    else
      $old_base_name($file,$ext)
};


Handle leading "/" on basex-supplied document URIs.

(: =====================================================

   DFST BaseX Utilities

   Utilities specific to the DFST use of BaseX for managing
   DITA content.

   Author: W. Eliot Kimber

   Copyright (c) 2015 DITA For Small Teams
   Licensed under Apache License 2

   ===================================================== :)

module namespace bxutil="http://dita-for-small-teams.org/xquery/modules/basex-utils";

(:~
 : getGitRepositoryInfos()
 :
 : Returns a list of zero or more <repo> elements, where each <repo>
 : element provides the repository name, branch count, and list of
 : branches in that repository.
 :
 : This function depends on the DFST BaseX database naming convention
 : of "d4st^{repo}^{branch}
 :
 :
 :)
 declare function bxutil:getGitRepositoryInfos() as element(repo)* {
  (: Organize the databases by repo. BaseX dbs for the same repo will start with the same string :)

  let $repos :=
      for $db in db:list-details() order by string($db)
          let $tokens := tokenize(string($db), '\^')
          return if ($tokens[1] = "d4st")
             then <repo name="{$tokens[2]}" branch="{$tokens[3]}"/>
             else ()

   (: Now select repos with the same repository name :)
   return for $name in distinct-values($repos/@name)
       return <repo name="{$name}" branchCount="{count($repos[@name = $name])}">{
              for $branch in $repos[@name = $name]
                  return <branch name="{$branch/@branch}"/>}</repo>

 };

 (: Constructs the BaseX database name for git repository and branch pair :)
 declare function bxutil:getDbNameForRepoAndBranch($repo, $branch) {
   let $sep := '^'
   return concat('d4st', $sep, $repo, $sep, $branch)
 };

 (: Constructs the BaseX metadata database name for git repository and branch pair
  : For each content database, reflecting a specific repository/branch pair,
  : there is a corresonding metadata database that holds any metadata for that
  : database (i.e., all the link management metadata).
  :)
 declare function bxutil:getMetadataDbNameForRepoAndBranch($repo, $branch) {
   let $sep := '^'
   return concat('_d4st', $sep, 'metadata', $sep, $repo, $sep, $branch)
 };

 (: Gets the metadata database name for given document.
  :
  :)
 declare function bxutil:getMetadataDbNameForDoc($doc as document-node()) {
   let $sep := '^'
   let $repo := bxutil:getGitRepoForDoc($doc)
   let $branch := bxutil:getGitBranchForDoc($doc)
   return bxutil:getMetadataDbNameForRepoAndBranch($repo, $branch)
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitRepoForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, '/d4st^'))
       then
         let $db := tokenize($uri, '/')[2] (: URL is '/foo/bar' so db is 2nd token :)
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/repo)
       else 'No associated git repository'
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitBranchForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, '/d4st^'))
       then
         let $db := tokenize($uri, '/')[2]   (: URL is '/foo/bar' so db is 2nd token :)
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/branch)
       else 'No associated git repository'
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitCommitForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, '/d4st^'))
       then
         let $db := tokenize($uri, '/')[2] (: URL is '/foo/bar' so db is 2nd token :)
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/commit)
       else 'No associated git repository'
 };

 (: Gets the git metadata document for the database :)
 declare function bxutil:getGitMetadata($db as xs:string) as element(d4st_metadata)? {
   let $uri as xs:string := concat($db, '/_d4st/metadata.xml')
   return
   try {
     doc($uri)/*
   } catch * {
     ()
   }

 };

 (: Given a document, returns the path to the doc, omitting the database name :)
 declare function bxutil:getPathForDoc($doc as document-node()) as xs:string? {
   bxutil:getPathForDocURI(document-uri($doc))
 };

 declare function bxutil:getPathForDocURI($uri as xs:string) as xs:string? {
   string-join(tokenize($uri, '/')[position() gt 2], '/') (: URI is '/foo/bar' so db is 2nd token :)
 };

 (:~
  : Report a map as XML for debugging purposes
  :
  : @return a sequence of zero or more elements, one for each
  : element in the map, where the tagname is the key name (assumes
  : string keys) and the contents are the serialized value of the
  : the map element.
  :)
declare function bxutil:reportMapAsXML($map as map(*)) as element()* {
   let $result :=
       for $key in map:keys($map)
           let $member := $map($key)
           return element item {
              attribute key { $key },
              typeswitch ($member)
                case attribute()
                  return <att name="{name($member)}">string($member)</att>
                case map(*)
                  return bxutil:reportMapAsXML($member)
                default
                  return $member
           }
    return $result
};
(: End of Module :)

(: =====================================================

   DFST BaseX Utilities

   Utilities specific to the DFST use of BaseX for managing
   DITA content.

   Author: W. Eliot Kimber

   Copyright (c) 2015 DITA For Small Teams
   Licensed under Apache License 2

   ===================================================== :)

module namespace bxutil="http://dita-for-small-teams.org/xquery/modules/basex-utils";

(:~
 : getGitRepositoryInfos()
 :
 : Returns a list of zero or more <repo> elements, where each <repo>
 : element provides the repository name, branch count, and list of
 : branches in that repository.
 :
 : This function depends on the DFST BaseX database naming convention
 : of "d4st^{repo}^{branch}
 :
 :
 :)
 declare function bxutil:getGitRepositoryInfos() as element(repo)* {
  (: Organize the databases by repo. BaseX dbs for the same repo will start with the same string :)

  let $repos :=
      for $db in db:list-details() order by string($db)
          let $tokens := tokenize(string($db), '\^')
          return if ($tokens[1] = "d4st")
             then <repo name="{$tokens[2]}" branch="{$tokens[3]}"/>
             else ()

   (: Now select repos with the same repository name :)
   return for $name in distinct-values($repos/@name)
       return <repo name="{$name}" branchCount="{count($repos[@name = $name])}">{
              for $branch in $repos[@name = $name]
                  return <branch name="{$branch/@branch}"/>}</repo>

 };

 (: Constructs the BaseX database name for git repository and branch pair :)
 declare function bxutil:getDbNameForRepoAndBranch($repo, $branch) {
   let $sep := '^'
   return concat('d4st', $sep, $repo, $sep, $branch)
 };

 (: Constructs the BaseX metadata database name for git repository and branch pair
  : For each content database, reflecting a specific repository/branch pair,
  : there is a corresonding metadata database that holds any metadata for that
  : database (i.e., all the link management metadata).
  :)
 declare function bxutil:getMetadataDbNameForRepoAndBranch($repo, $branch) {
   let $sep := '^'
   return concat('_d4st', $sep, 'metadata', $sep, $repo, $sep, $branch)
 };

 (: Gets the metadata database name for given document.
  :
  :)
 declare function bxutil:getMetadataDbNameForDoc($doc as document-node()) {
   let $sep := '^'
   let $repo := bxutil:getGitRepoForDoc($doc)
   let $branch := bxutil:getGitBranchForDoc($doc)
   return bxutil:getMetadataDbNameForRepoAndBranch($repo, $branch)
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitRepoForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, 'd4st^'))
       then
         let $db := tokenize($uri, '/')[1]
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/repo)
       else 'No associated git repository'
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitBranchForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, 'd4st^'))
       then
         let $db := tokenize($uri, '/')[1]
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/branch)
       else 'No associated git repository'
 };

 (: Gets the git repository for a document  :)
 declare function bxutil:getGitCommitForDoc($doc as document-node()) {
    let $uri := document-uri($doc)
    return if (starts-with($uri, 'd4st^'))
       then
         let $db := tokenize($uri, '/')[1]
         let $gitMetadata := bxutil:getGitMetadata($db)
         return string($gitMetadata/gitstate/commit)
       else 'No associated git repository'
 };

 (: Gets the git metadata document for the database :)
 declare function bxutil:getGitMetadata($db as xs:string) as element(d4st_metadata)? {
   let $uri as xs:string := concat($db, '/_d4st/metadata.xml')
   return
   try {
     doc($uri)/*
   } catch * {
     ()
   }

 };

 (: Given a document, returns the path to the doc, omitting the database name :)
 declare function bxutil:getPathForDoc($doc as document-node()) as xs:string? {
   bxutil:getPathForDocURI(document-uri($doc))
 };

 declare function bxutil:getPathForDocURI($uri as xs:string) as xs:string? {
   string-join(tokenize($uri, '/')[position() gt 1], '/')
 };

 (:~
  : Report a map as XML for debugging purposes
  :
  : @return a sequence of zero or more elements, one for each
  : element in the map, where the tagname is the key name (assumes
  : string keys) and the contents are the serialized value of the
  : the map element.
  :)
declare function bxutil:reportMapAsXML($map as map(*)) as element()* {
   let $result :=
       for $key in map:keys($map)
           let $member := $map($key)
           return element item {
              attribute key { $key },
              typeswitch ($member)
                case attribute()
                  return <att name="{name($member)}">string($member)</att>
                case map(*)
                  return bxutil:reportMapAsXML($member)
                default
                  return $member
           }
    return $result
};
(: End of Module :)


fix create document action

fix create document action

module namespace page = 'http://basex.org/modules/web-page';

import module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";
import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
import module namespace csd_webui =  "https://github.com/openhie/openinfoman/csd_webui";

declare updating
  %rest:path("/CSD/createDirectory")
  %rest:POST
  %rest:form-param("directory","{$directory}")
  %output:method("xhtml")
  function page:create_directory($directory)
{
   (
     if (not (csd_dm:document_source_exists($csd_webconf:db,$directory))) then
       csd_dm:empty($csd_webconf:db,$directory)
     else ()
     ,
   csd_webui:redirect_out("CSD")
  )
};

declare
  %rest:path("/CSD")
  %rest:GET
  %output:method("xhtml")
  function page:list_functionality()
{
  let $what_is_dm :=

    The document manger registers documents to perform  careServicesRequests and getUpdatedServices requests  against.  Registered documents can be any of:

Local cache of a remote service directory -- this is useful for turning a Care Services Directory into an Open Info Manager

Sample Directories -- these loaded from an XML source file on the system and are useful for testing

The merged result of remote service directories

  let $csd :=

    {$what_is_dm}

      {let $docs := csd_dm:registered_documents($csd_webconf:db)
      return (
	  "You have ", count($docs) , " registered document(s) available: ",

	    {
	      for $doc in $docs
	      return

		 {$doc}
		 [
		   Empty
		  /  Delete
		  ]

	    }

	  )
      }

Create Blank Directory

      <form method='post' action="{csd_webui:generateURL(('CSD/getDirectory/'))}">
	<input name='directory' type='text'/>
	<input type='submit' value='Create'/>
      </form>

  let $svs :=

    In addition, there is some initial support for use of terminologies using the Sharing Value Sets(SVS) profile from IHE:

load Shared Value Sets

available Shared Value Sets

  let $adapters :=

        {
	  let $docs := csd_dm:registered_documents($csd_webconf:db)
	  return (
	    "You have ", count($docs) , " registered document(s) available: ",

	      {
		for $doc in $docs
		return

		   {$doc}
		  [
		   View Stored Functions
		  ]

	      }

	  )
	}

List of all API  adapters for stored functions: CSD Adapters

  let $generic :=

These the top-level endpoints are exposed

Manage Stored Functions

Load and Register Sample Service Directories

Register and Poll Remote Service Service directories

Execute Ad-Hoc Care Services Requests and View Care Service Request Endpoints for Registered Documents

Endpoints for submitting getUpdatedServices Soap Request for Registered Documents

Manage duplicate record identifiers

  return csd_webui:nocache(page:wrapper($csd,$svs,$adapters,$generic))
};

declare
  %rest:path("/CSD/getDirectory/{$name}")
  %rest:GET
  function page:get_directory($name)
{
  csd_dm:open_document($csd_webconf:db,$name)
};

declare updating
  %rest:path("/CSD/emptyDirectory/{$name}")
  %rest:GET
  function page:empty_directory($name)
{
  (
    csd_dm:empty($csd_webconf:db,$name)
    ,csd_webui:redirect_out("CSD")
  )
};

declare updating
  %rest:path("/CSD/deleteDirectory/{$name}")
  %rest:GET
  function page:delete_directory($name)
{
  (
    csd_dm:delete($csd_webconf:db,$name)
    ,csd_webui:redirect_out("CSD")
  )
};

declare function page:wrapper($csd,$svs,$adapters) {
  page:wrapper($csd,$svs,$adapters,())
};

declare function page:wrapper($csd,$svs,$adapters,$generic_csd) {
  let $generic :=

OpenInfoMan has been developed as part of OpenHIE and is intended to be the engine behind the CSD compliant Health Worker Registry and to be incorporated in OpenHIM.

    Source code is on github

  let $headers :=  (
    <link rel="stylesheet" type="text/css" media="screen"   href="{csd_webui:generateURL('static/bootstrap/js/tab.js')}"/>
    ,

    )
    let $content := (

Introduction

Server Managment

Terminolgies

Documents

      ,

Welcome to OpenInfoMan

		  OpenInfoMan is an XQuery and RESTXQ based implementation of the Care Services Directory (CSD) profile from IHE which implements the following actors and transactions:

		    Info Manager :

		    Find Matching Services (Ad-Hoc and Stored) [ITI-73]

		    Query for  Updated Services Transaction [ITI-74]

		    Services Directory :

Query for  Updated Services Transaction [ITI-74]

		{$generic}

	      {$generic}
	      {$generic_csd}

	      {$csd}

	      {$generic}

	      {$svs}

	      {$generic}

	      {$adapters}

      )

  return csd_webui:wrapper($content,$headers)
};

module namespace page = 'http://basex.org/modules/web-page';

import module namespace csd_dm = "https://github.com/openhie/openinfoman/csd_dm";
import module namespace csd_webconf =  "https://github.com/openhie/openinfoman/csd_webconf";
import module namespace csd_webui =  "https://github.com/openhie/openinfoman/csd_webui";

declare updating
  %rest:path("/CSD/createDirectory")
  %rest:POST
  %rest:form-param("directory","{$directory}")
  %output:method("xhtml")
  function page:create_directory($directory)
{
   (
     if (not (csd_dm:document_source_exists($csd_webconf:db,$directory))) then
       csd_dm:empty($csd_webconf:db,$directory)
     else ()
     ,
   csd_webui:redirect_out("CSD")
  )
};

declare
  %rest:path("/CSD")
  %rest:GET
  %output:method("xhtml")
  function page:list_functionality()
{
  let $what_is_dm :=

    The document manger registers documents to perform  careServicesRequests and getUpdatedServices requests  against.  Registered documents can be any of:

Local cache of a remote service directory -- this is useful for turning a Care Services Directory into an Open Info Manager

Sample Directories -- these loaded from an XML source file on the system and are useful for testing

The merged result of remote service directories

  let $csd :=

    {$what_is_dm}

      {let $docs := csd_dm:registered_documents($csd_webconf:db)
      return (
	  "You have ", count($docs) , " registered document(s) available: ",

	    {
	      for $doc in $docs
	      return

		 {$doc}
		 [
		   Empty
		  /  Delete
		  ]

	    }

	  )
      }

Create Blank Directory

      <form method='post' action="/CSD/createDirectory">
	<input name='directory' type='text'/>
	<input type='submit' value='Create'/>
      </form>

  let $svs :=

    In addition, there is some initial support for use of terminologies using the Sharing Value Sets(SVS) profile from IHE:

load Shared Value Sets

available Shared Value Sets

  let $adapters :=

        {
	  let $docs := csd_dm:registered_documents($csd_webconf:db)
	  return (
	    "You have ", count($docs) , " registered document(s) available: ",

	      {
		for $doc in $docs
		return

		   {$doc}
		  [
		   View Stored Functions
		  ]

	      }

	  )
	}

List of all API  adapters for stored functions: CSD Adapters

  let $generic :=

These the top-level endpoints are exposed

Manage Stored Functions

Load and Register Sample Service Directories

Register and Poll Remote Service Service directories

Execute Ad-Hoc Care Services Requests and View Care Service Request Endpoints for Registered Documents

Endpoints for submitting getUpdatedServices Soap Request for Registered Documents

Manage duplicate record identifiers

  return csd_webui:nocache(page:wrapper($csd,$svs,$adapters,$generic))
};

declare
  %rest:path("/CSD/getDirectory/{$name}")
  %rest:GET
  function page:get_directory($name)
{
  csd_dm:open_document($csd_webconf:db,$name)
};

declare updating
  %rest:path("/CSD/emptyDirectory/{$name}")
  %rest:GET
  function page:empty_directory($name)
{
  (
    csd_dm:empty($csd_webconf:db,$name)
    ,csd_webui:redirect_out("CSD")
  )
};

declare updating
  %rest:path("/CSD/deleteDirectory/{$name}")
  %rest:GET
  function page:delete_directory($name)
{
  (
    csd_dm:delete($csd_webconf:db,$name)
    ,csd_webui:redirect_out("CSD")
  )
};

declare function page:wrapper($csd,$svs,$adapters) {
  page:wrapper($csd,$svs,$adapters,())
};

declare function page:wrapper($csd,$svs,$adapters,$generic_csd) {
  let $generic :=

OpenInfoMan has been developed as part of OpenHIE and is intended to be the engine behind the CSD compliant Health Worker Registry and to be incorporated in OpenHIM.

    Source code is on github

  let $headers :=  (
    <link rel="stylesheet" type="text/css" media="screen"   href="{csd_webui:generateURL('static/bootstrap/js/tab.js')}"/>
    ,

    )
    let $content := (

Introduction

Server Managment

Terminolgies

Documents

      ,

Welcome to OpenInfoMan

		  OpenInfoMan is an XQuery and RESTXQ based implementation of the Care Services Directory (CSD) profile from IHE which implements the following actors and transactions:

		    Info Manager :

		    Find Matching Services (Ad-Hoc and Stored) [ITI-73]

		    Query for  Updated Services Transaction [ITI-74]

		    Services Directory :

Query for  Updated Services Transaction [ITI-74]

		{$generic}

	      {$generic}
	      {$generic_csd}

	      {$csd}

	      {$generic}

	      {$svs}

	      {$generic}

	      {$adapters}

      )

  return csd_webui:wrapper($content,$headers)
};


Don't list MarkLogic log files that have 0 size.

(:
 : Copyright (C) 2019 Reece H. Dunn
 :
 : 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.
 :)
xquery version "1.0-ml";
declare namespace o = "http://reecedunn.co.uk/xquery/options";
declare option o:implementation "marklogic/6.0";

(: Return the log files on the MarkLogic server. :)

declare variable $separator := if (xdmp:platform() = "winnt") then "\" else "/";
declare variable $logs-path := xdmp:data-directory() || $separator || "Logs";

for $log in xdmp:filesystem-directory($logs-path)/dir:entry
where $log/dir:content-length/data() gt 0
return $log/dir:filename/text()

(:
 : Copyright (C) 2019 Reece H. Dunn
 :
 : 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.
 :)
xquery version "1.0-ml";
declare namespace o = "http://reecedunn.co.uk/xquery/options";
declare option o:implementation "marklogic/6.0";

(: Return the log files on the MarkLogic server. :)

declare variable $separator := if (xdmp:platform() = "winnt") then "\" else "/";
declare variable $logs-path := xdmp:data-directory() || $separator || "Logs";

xdmp:filesystem-directory($logs-path)/dir:entry/dir:filename/text()


Add a %since(version, date) annotation to the fn built-in functions.

xquery version "3.0";

(:~
 : XQuery 1.0 and XPath 2.0 Functions and Operators
 : W3C Recommendation 23 January 2007
 :
 : @see https://www.w3.org/TR/2007/REC-xpath-functions-20070123/
 :)
module  namespace fn = "http://www.w3.org/2005/xpath-functions";
declare namespace xs = "http://www.w3.org/2001/XMLSchema";

declare %since("1.0", "20070123") function fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName external;
declare %since("1.0", "20070123") function fn:abs($arg as xs:numeric?) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:adjust-date-to-timezone($arg as xs:date?) as xs:date? external;
declare %since("1.0", "20070123") function fn:adjust-date-to-timezone($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date? external;
declare %since("1.0", "20070123") function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?) as xs:dateTime? external;
declare %since("1.0", "20070123") function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime? external;
declare %since("1.0", "20070123") function fn:adjust-time-to-timezone($arg as xs:time?) as xs:time? external;
declare %since("1.0", "20070123") function fn:adjust-time-to-timezone($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time? external;
declare %since("1.0", "20070123") function fn:avg($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:base-uri() as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:base-uri($arg as node()?) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:boolean($arg as item()*) as xs:boolean external;
declare %since("1.0", "20070123") function fn:ceiling($arg as xs:numeric?) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:codepoint-equal($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean? external;
declare %since("1.0", "20070123") function fn:codepoints-to-string($arg as xs:integer*) as xs:string external;
declare %since("1.0", "20070123") function fn:collection() as node()* external;
declare %since("1.0", "20070123") function fn:collection($arg as xs:string?) as node()* external;
declare %since("1.0", "20070123") function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? external;
declare %since("1.0", "20070123") %variadic("xs:anyAtomicType?") function fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?) as xs:string external;
declare %since("1.0", "20070123") function fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare %since("1.0", "20070123") function fn:contains($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:count($arg as item()*) as xs:integer external;
declare %since("1.0", "20070123") function fn:current-date() as xs:date external;
declare %since("1.0", "20070123") function fn:current-dateTime() as xs:dateTime external;
declare %since("1.0", "20070123") function fn:current-time() as xs:time external;
declare %since("1.0", "20070123") function fn:data($arg as item()*) as xs:anyAtomicType* external;
declare %since("1.0", "20070123") function fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? external;
declare %since("1.0", "20070123") function fn:day-from-date($arg as xs:date?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:days-from-duration($arg as xs:duration?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*) as xs:boolean external;
declare %since("1.0", "20070123") function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*, $collation as string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:default-collation() as xs:string external;
declare %since("1.0", "20070123") function fn:distinct-values($arg as xs:anyAtomicType*) as xs:anyAtomicType* external;
declare %since("1.0", "20070123") function fn:distinct-values($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType* external;
declare %since("1.0", "20070123") function fn:doc($uri as xs:string?) as document-node()? external;
declare %since("1.0", "20070123") function fn:doc-available($uri as xs:string?) as xs:boolean external;
declare %since("1.0", "20070123") function fn:document-uri($arg as node()?) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:empty($arg as item()*) as xs:boolean external;
declare %since("1.0", "20070123") function fn:encode-for-uri($uri-part as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare %since("1.0", "20070123") function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:error() as none external;
declare %since("1.0", "20070123") function fn:error($error as xs:QName) as none external;
declare %since("1.0", "20070123") function fn:error($error as xs:QName?, $description as xs:string) as none external;
declare %since("1.0", "20070123") function fn:error($error as xs:QName?, $description as xs:string, $error-object as item()*) as none external;
declare %since("1.0", "20070123") function fn:escape-html-uri($uri as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:exactly-one($arg as item()*) as item() external;
declare %since("1.0", "20070123") function fn:exists($arg as item()*) as xs:boolean external;
declare %since("1.0", "20070123") function fn:false() as xs:boolean external;
declare %since("1.0", "20070123") function fn:floor($arg as xs:numeric?) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:hours-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:hours-from-duration($arg as xs:duration?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:hours-from-time($arg as xs:time?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:id($arg as xs:string*) as element()* external;
declare %since("1.0", "20070123") function fn:id($arg as xs:string*, $node as node()) as element()* external;
declare %since("1.0", "20070123") function fn:idref($arg as xs:string*) as node()* external;
declare %since("1.0", "20070123") function fn:idref($arg as xs:string*, $node as node()) as node()* external;
declare %since("1.0", "20070123") function fn:implicit-timezone() as xs:dayTimeDuration external;
declare %since("1.0", "20070123") function fn:in-scope-prefixes($element as element()) as xs:string* external;
declare %since("1.0", "20070123") function fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType) as xs:integer* external;
declare %since("1.0", "20070123") function fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType, $collation as xs:string) as xs:integer* external;
declare %since("1.0", "20070123") function fn:insert-before($target as item()*, $position as xs:integer, $inserts as item()*) as item()* external;
declare %since("1.0", "20070123") function fn:iri-to-uri($iri as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:lang($testlang as xs:string?) as xs:boolean external;
declare %since("1.0", "20070123") function fn:lang($testlang as xs:string?, $node as node()) as xs:boolean external;
declare %since("1.0", "20070123") function fn:last() as xs:integer external;
declare %since("1.0", "20070123") function fn:local-name() as xs:string external;
declare %since("1.0", "20070123") function fn:local-name($arg as node()?) as xs:string external;
declare %since("1.0", "20070123") function fn:local-name-from-QName($arg as xs:QName?) as xs:NCName? external;
declare %since("1.0", "20070123") function fn:lower-case($arg as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:matches($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:max($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:max($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:min($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:min($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:minutes-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:minutes-from-duration($arg as xs:duration?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:minutes-from-time($arg as xs:time?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:month-from-date($arg as xs:date?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:month-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:months-from-duration($arg as xs:duration?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:name() as xs:string external;
declare %since("1.0", "20070123") function fn:name($arg as node()?) as xs:string external;
declare %since("1.0", "20070123") function fn:namespace-uri() as xs:anyURI external;
declare %since("1.0", "20070123") function fn:namespace-uri($arg as node()?) as xs:anyURI external;
declare %since("1.0", "20070123") function fn:namespace-uri-for-prefix($prefix as xs:string?, $element as element()) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:nilled($arg as node()?) as xs:boolean? external;
declare %since("1.0", "20070123") function fn:node-name($arg as node()?) as xs:QName? external;
declare %since("1.0", "20070123") function fn:normalize-space() as xs:string external;
declare %since("1.0", "20070123") function fn:normalize-space($arg as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:normalize-unicode($arg as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:normalize-unicode($arg as xs:string?, $normalizationForm as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:not($arg as item()*) as xs:boolean external;
declare %since("1.0", "20070123") function fn:number() as xs:double external;
declare %since("1.0", "20070123") function fn:number($arg as xs:anyAtomicType?) as xs:double external;
declare %since("1.0", "20070123") function fn:one-or-more($arg as item()*) as item()+ external;
declare %since("1.0", "20070123") function fn:position() as xs:integer external;
declare %since("1.0", "20070123") function fn:prefix-from-QName($arg as xs:QName?) as xs:NCName? external;
declare %since("1.0", "20070123") function fn:remove($target as item()*, $position as xs:integer) as item()* external;
declare %since("1.0", "20070123") function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:resolve-QName($qname as xs:string?, $element as element()) as xs:QName? external;
declare %since("1.0", "20070123") function fn:resolve-uri($relative as xs:string?) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:reverse($arg as item()*) as item()* external;
declare %since("1.0", "20070123") function fn:root() as node() external;
declare %since("1.0", "20070123") function fn:root($arg as node()?) as node()? external;
declare %since("1.0", "20070123") function fn:round($arg as xs:numeric?) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:round-half-to-even($arg as xs:numeric?) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:round-half-to-even($arg as xs:numeric?, $precision as xs:integer) as xs:numeric? external;
declare %since("1.0", "20070123") function fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal? external;
declare %since("1.0", "20070123") function fn:seconds-from-duration($arg as xs:duration?) as xs:decimal? external;
declare %since("1.0", "20070123") function fn:seconds-from-time($arg as xs:time?) as xs:decimal? external;
declare %since("1.0", "20070123") function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare %since("1.0", "20070123") function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare %since("1.0", "20070123") function fn:static-base-uri() as xs:anyURI? external;
declare %since("1.0", "20070123") function fn:string() as xs:string external;
declare %since("1.0", "20070123") function fn:string($arg as item()?) as xs:string external;
declare %since("1.0", "20070123") function fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:string-length() as xs:integer external;
declare %since("1.0", "20070123") function fn:string-length($arg as xs:string?) as xs:integer external;
declare %since("1.0", "20070123") function fn:string-to-codepoints($arg as xs:string?) as xs:integer* external;
declare %since("1.0", "20070123") function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double) as item()* external;
declare %since("1.0", "20070123") function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()* external;
declare %since("1.0", "20070123") function fn:substring($sourceString as xs:string?, $startingLoc as xs:double) as xs:string external;
declare %since("1.0", "20070123") function fn:substring($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) as xs:string external;
declare %since("1.0", "20070123") function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:sum($arg as xs:anyAtomicType*) as xs:anyAtomicType external;
declare %since("1.0", "20070123") function fn:sum($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType? external;
declare %since("1.0", "20070123") function fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration? external;
declare %since("1.0", "20070123") function fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration? external;
declare %since("1.0", "20070123") function fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration? external;
declare %since("1.0", "20070123") function fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string* external;
declare %since("1.0", "20070123") function fn:tokenize($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string* external;
declare %since("1.0", "20070123") function fn:trace($value as item()*, $label as xs:string) as item()* external;
declare %since("1.0", "20070123") function fn:translate($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string external;
declare %since("1.0", "20070123") function fn:true() as xs:boolean external;
declare %since("1.0", "20070123") function fn:unordered($sourceSeq as item()*) as item()* external;
declare %since("1.0", "20070123") function fn:upper-case($arg as xs:string?) as xs:string external;
declare %since("1.0", "20070123") function fn:year-from-date($arg as xs:date?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:year-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:years-from-duration($arg as xs:duration?) as xs:integer? external;
declare %since("1.0", "20070123") function fn:zero-or-one($arg as item()*) as item()? external;

xquery version "3.0";

(:~
 : XQuery 1.0 and XPath 2.0 Functions and Operators
 : W3C Recommendation 23 January 2007
 :
 : @see https://www.w3.org/TR/2007/REC-xpath-functions-20070123/
 :)
module  namespace fn = "http://www.w3.org/2005/xpath-functions";
declare namespace xs = "http://www.w3.org/2001/XMLSchema";

declare function fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName external;
declare function fn:abs($arg as xs:numeric?) as xs:numeric? external;
declare function fn:adjust-date-to-timezone($arg as xs:date?) as xs:date? external;
declare function fn:adjust-date-to-timezone($arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date? external;
declare function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?) as xs:dateTime? external;
declare function fn:adjust-dateTime-to-timezone($arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime? external;
declare function fn:adjust-time-to-timezone($arg as xs:time?) as xs:time? external;
declare function fn:adjust-time-to-timezone($arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time? external;
declare function fn:avg($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare function fn:base-uri() as xs:anyURI? external;
declare function fn:base-uri($arg as node()?) as xs:anyURI? external;
declare function fn:boolean($arg as item()*) as xs:boolean external;
declare function fn:ceiling($arg as xs:numeric?) as xs:numeric? external;
declare function fn:codepoint-equal($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean? external;
declare function fn:codepoints-to-string($arg as xs:integer*) as xs:string external;
declare function fn:collection() as node()* external;
declare function fn:collection($arg as xs:string?) as node()* external;
declare function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer? external;
declare function fn:compare($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer? external;
declare %variadic("xs:anyAtomicType?") function fn:concat($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?) as xs:string external;
declare function fn:contains($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare function fn:contains($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare function fn:count($arg as item()*) as xs:integer external;
declare function fn:current-date() as xs:date external;
declare function fn:current-dateTime() as xs:dateTime external;
declare function fn:current-time() as xs:time external;
declare function fn:data($arg as item()*) as xs:anyAtomicType* external;
declare function fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? external;
declare function fn:day-from-date($arg as xs:date?) as xs:integer? external;
declare function fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare function fn:days-from-duration($arg as xs:duration?) as xs:integer? external;
declare function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*) as xs:boolean external;
declare function fn:deep-equal($parameter1 as item()*, $parameter2 as item()*, $collation as string) as xs:boolean external;
declare function fn:default-collation() as xs:string external;
declare function fn:distinct-values($arg as xs:anyAtomicType*) as xs:anyAtomicType* external;
declare function fn:distinct-values($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType* external;
declare function fn:doc($uri as xs:string?) as document-node()? external;
declare function fn:doc-available($uri as xs:string?) as xs:boolean external;
declare function fn:document-uri($arg as node()?) as xs:anyURI? external;
declare function fn:empty($arg as item()*) as xs:boolean external;
declare function fn:encode-for-uri($uri-part as xs:string?) as xs:string external;
declare function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare function fn:ends-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare function fn:error() as none external;
declare function fn:error($error as xs:QName) as none external;
declare function fn:error($error as xs:QName?, $description as xs:string) as none external;
declare function fn:error($error as xs:QName?, $description as xs:string, $error-object as item()*) as none external;
declare function fn:escape-html-uri($uri as xs:string?) as xs:string external;
declare function fn:exactly-one($arg as item()*) as item() external;
declare function fn:exists($arg as item()*) as xs:boolean external;
declare function fn:false() as xs:boolean external;
declare function fn:floor($arg as xs:numeric?) as xs:numeric? external;
declare function fn:hours-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare function fn:hours-from-duration($arg as xs:duration?) as xs:integer? external;
declare function fn:hours-from-time($arg as xs:time?) as xs:integer? external;
declare function fn:id($arg as xs:string*) as element()* external;
declare function fn:id($arg as xs:string*, $node as node()) as element()* external;
declare function fn:idref($arg as xs:string*) as node()* external;
declare function fn:idref($arg as xs:string*, $node as node()) as node()* external;
declare function fn:implicit-timezone() as xs:dayTimeDuration external;
declare function fn:in-scope-prefixes($element as element()) as xs:string* external;
declare function fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType) as xs:integer* external;
declare function fn:index-of($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType, $collation as xs:string) as xs:integer* external;
declare function fn:insert-before($target as item()*, $position as xs:integer, $inserts as item()*) as item()* external;
declare function fn:iri-to-uri($iri as xs:string?) as xs:string external;
declare function fn:lang($testlang as xs:string?) as xs:boolean external;
declare function fn:lang($testlang as xs:string?, $node as node()) as xs:boolean external;
declare function fn:last() as xs:integer external;
declare function fn:local-name() as xs:string external;
declare function fn:local-name($arg as node()?) as xs:string external;
declare function fn:local-name-from-QName($arg as xs:QName?) as xs:NCName? external;
declare function fn:lower-case($arg as xs:string?) as xs:string external;
declare function fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean external;
declare function fn:matches($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean external;
declare function fn:max($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare function fn:max($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType? external;
declare function fn:min($arg as xs:anyAtomicType*) as xs:anyAtomicType? external;
declare function fn:min($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType? external;
declare function fn:minutes-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare function fn:minutes-from-duration($arg as xs:duration?) as xs:integer? external;
declare function fn:minutes-from-time($arg as xs:time?) as xs:integer? external;
declare function fn:month-from-date($arg as xs:date?) as xs:integer? external;
declare function fn:month-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare function fn:months-from-duration($arg as xs:duration?) as xs:integer? external;
declare function fn:name() as xs:string external;
declare function fn:name($arg as node()?) as xs:string external;
declare function fn:namespace-uri() as xs:anyURI external;
declare function fn:namespace-uri($arg as node()?) as xs:anyURI external;
declare function fn:namespace-uri-for-prefix($prefix as xs:string?, $element as element()) as xs:anyURI? external;
declare function fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI? external;
declare function fn:nilled($arg as node()?) as xs:boolean? external;
declare function fn:node-name($arg as node()?) as xs:QName? external;
declare function fn:normalize-space() as xs:string external;
declare function fn:normalize-space($arg as xs:string?) as xs:string external;
declare function fn:normalize-unicode($arg as xs:string?) as xs:string external;
declare function fn:normalize-unicode($arg as xs:string?, $normalizationForm as xs:string) as xs:string external;
declare function fn:not($arg as item()*) as xs:boolean external;
declare function fn:number() as xs:double external;
declare function fn:number($arg as xs:anyAtomicType?) as xs:double external;
declare function fn:one-or-more($arg as item()*) as item()+ external;
declare function fn:position() as xs:integer external;
declare function fn:prefix-from-QName($arg as xs:QName?) as xs:NCName? external;
declare function fn:remove($target as item()*, $position as xs:integer) as item()* external;
declare function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string external;
declare function fn:replace($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string external;
declare function fn:resolve-QName($qname as xs:string?, $element as element()) as xs:QName? external;
declare function fn:resolve-uri($relative as xs:string?) as xs:anyURI? external;
declare function fn:resolve-uri($relative as xs:string?, $base as xs:string) as xs:anyURI? external;
declare function fn:reverse($arg as item()*) as item()* external;
declare function fn:root() as node() external;
declare function fn:root($arg as node()?) as node()? external;
declare function fn:round($arg as xs:numeric?) as xs:numeric? external;
declare function fn:round-half-to-even($arg as xs:numeric?) as xs:numeric? external;
declare function fn:round-half-to-even($arg as xs:numeric?, $precision as xs:integer) as xs:numeric? external;
declare function fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal? external;
declare function fn:seconds-from-duration($arg as xs:duration?) as xs:decimal? external;
declare function fn:seconds-from-time($arg as xs:time?) as xs:decimal? external;
declare function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean external;
declare function fn:starts-with($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean external;
declare function fn:static-base-uri() as xs:anyURI? external;
declare function fn:string() as xs:string external;
declare function fn:string($arg as item()?) as xs:string external;
declare function fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string external;
declare function fn:string-length() as xs:integer external;
declare function fn:string-length($arg as xs:string?) as xs:integer external;
declare function fn:string-to-codepoints($arg as xs:string?) as xs:integer* external;
declare function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double) as item()* external;
declare function fn:subsequence($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()* external;
declare function fn:substring($sourceString as xs:string?, $startingLoc as xs:double) as xs:string external;
declare function fn:substring($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) as xs:string external;
declare function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external;
declare function fn:substring-after($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external;
declare function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?) as xs:string external;
declare function fn:substring-before($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string external;
declare function fn:sum($arg as xs:anyAtomicType*) as xs:anyAtomicType external;
declare function fn:sum($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType? external;
declare function fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration? external;
declare function fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration? external;
declare function fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration? external;
declare function fn:tokenize($input as xs:string?, $pattern as xs:string) as xs:string* external;
declare function fn:tokenize($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string* external;
declare function fn:trace($value as item()*, $label as xs:string) as item()* external;
declare function fn:translate($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string external;
declare function fn:true() as xs:boolean external;
declare function fn:unordered($sourceSeq as item()*) as item()* external;
declare function fn:upper-case($arg as xs:string?) as xs:string external;
declare function fn:year-from-date($arg as xs:date?) as xs:integer? external;
declare function fn:year-from-dateTime($arg as xs:dateTime?) as xs:integer? external;
declare function fn:years-from-duration($arg as xs:duration?) as xs:integer? external;
declare function fn:zero-or-one($arg as item()*) as item()? external;