[MOD] Aligned with latest version... $util:nl -> util:nl()

(:~
 : Conversion module for creating JUnit tests from the QT3TS test suite.
 : @author Leo Woerteler
 : @version 0.1
 :)
module namespace qt3ts='http://www.basex.org/modules/qt3ts';

import module namespace qt3ts-java='http://www.basex.org/modules/qt3ts/java'
  at 'qt3ts-java.xqm';

declare default element namespace 'http://www.w3.org/2010/09/qt-fots-catalog';

(:~
 : Main entry point.
 : @param $path path to the test-suite
 : @param $test-sets to be converted
 : @param $package Java package
 : @param $out-path path for the generated Java files
 : @return nothing
 :)
declare function qt3ts:to-junit(
  $path as xs:string,
  $test-sets as xs:string*,
  $package as xs:string,
  $out-path as xs:string,
  $supports as function(xs:string, xs:string*) as xs:boolean
) as empty-sequence() {
  let $catalog := doc($path || file:dir-separator() || 'catalog.xml'),
      $root    := replace(base-uri($catalog), 'catalog\.xml$', ''),
      $files   := qt3ts:get-files($root, $catalog),
      $envs    := qt3ts:environments(map:new(), $catalog/catalog/environment, $files)
  let $files   :=
        qt3ts-java:test-suites(
          $package,
          map:new((
            for $test-set in
              if($test-sets = '*') then $catalog//test-set
              else
                for $name in $test-sets
                let $set := $catalog//test-set[@name = $name]
                return if($set) then $set else qt3ts:debug('Test-set not found', $name)
            return qt3ts:test-set($test-set, $root, $package, $supports, $envs)
          ))
        )
  for $name in map:keys($files)
  let $path := $out-path || file:dir-separator() || $name || '.java'
  return (
    file:create-dir(replace($path, '[^/\\]+$', '')),
    file:write($path, $files($name), map{ 'method' := 'text' })
  )
};

(:~
 : Processes a test-set.
 : @param $test-set the test-set element
 : @param $package Java package
 : @param $out-path path for the generated Java files
 : @return full class name
 :)
declare function qt3ts:test-set(
  $test-set as element(test-set),
  $root as xs:string,
  $package as xs:string,
  $supports as function(xs:string, xs:string*) as xs:boolean,
  $envs as map(*)
) as map(*)? {
  let $name := $test-set/@name/string(),
      $dir  := replace($test-set/@file, '/[^/]+$', ''),
      $path := $root || $test-set/@file,
      $doc  := doc($path),
      $file := qt3ts:get-files($root, $doc),
      $envs := qt3ts:environments($envs, $doc/test-set/environment, $file),
      $desc := if($doc/test-set/description)
                 then $doc/test-set/description/string()
                 else 'Test-set ' || $name || '.'
  let $tests := map:new((
    for $test-case in $doc/test-set/test-case
    where every $dep in $test-case/dependency
      satisfies $supports($dep/@type, tokenize($dep/@value, ' '))
    return map{ $test-case/@name := qt3ts:test-case($test-set, $test-case, $root, $envs, $file) }
  ))
  return if(map:size($tests) gt 0)
    then
      let $ts := qt3ts-java:test-set($package, $dir, $name, $desc, $tests)
      return if(contains($ts[2], ' void '))
        then map:entry($dir || '/' || $ts[1], $ts[2])
        else qt3ts:debug('Test-set skipped after serialization', $name)
    else qt3ts:debug('Test-set skipped', $name)
};

declare function qt3ts:test-case(
  $test-set as element(test-set),
  $test-case as element(test-case),
  $root as xs:string,
  $envs as map(*),
  $file as map(*)
) as map(*) {
  let $desc := $test-case/description/string(),
      $env := $test-case/environment,
      $mods := map:new((
          for $mod in $test-case/module
          return map:entry(
            xs:anyURI($mod/@uri/string()),
            $file($mod/@file)
          )
        )),
      $map :=
        if($env) then
          if($env/@ref) then
            if(map:contains($envs, $env/@ref))
              then $envs($env/@ref)
              else (
                qt3ts:debug('Couldn''t find environment',
                  $test-set/@name || ', ' || $env/@ref),
                map{}
              )
          else qt3ts:environment($env, $file)
        else map{},
      $test := if($test-case/test/@file)
        then qt3ts:read-test($test-set, $test-case)
        else $test-case/test/string(),
      $result := qt3ts:result($test-case/result/*, $file, $root)
  return map{
    'description' := $desc,
    'modules'     := $mods,
    'environment' := $map,
    'test'        := $test,
    'result'      := $result
  }
};

declare function qt3ts:result(
  $assert as element(),
  $file as map(*),
  $root as xs:string
) as map(*) {
  let $name := $assert/local-name()
  return map:entry($name,
    switch($name)
      case 'assert-true' return ()
      case 'assert-false' return ()
      case 'assert-empty' return ()
      case 'assert' return $assert/string()
      case 'assert-eq' return $assert/string()
      case 'assert-string-value' return map{
          'normalize-space' := $assert/@normalize-space = ('true', '1'),
          'result'          := $assert/string()
        }
      case 'assert-permutation' return $assert/string()
      case 'assert-type' return $assert/string()
      case 'assert-deep-eq' return $assert/string()
      case 'assert-count' return xs:integer($assert/string())
      case 'error' return $assert/@code/string()
      case 'assert-serialization-error' return $assert/@code/string()
      case 'assert-serialization' return map{
          'ignore-prefixes' := $assert/@ignore-prefixes = ('true', '1'),
          'result' := if($assert/@file)
            then
              let $path := $root || $file($assert/@file)
              return unparsed-text($path, 'UTF-8')
            else $assert/string()
        }
      case 'all-of' return map(qt3ts:result(?, $file, $root), $assert/*)
      case 'any-of' return map(qt3ts:result(?, $file, $root), $assert/*)
      default return qt3ts:debug('Unknown assertion', $name)
  )
};

declare function qt3ts:read-test(
  $test-set as element(test-set),
  $test-case as element(test-case)
) as xs:string {
  let $path := replace(base-uri($test-case), '[^/]+$', $test-case/test/@file)
  return unparsed-text($path, 'UTF-8')
};

declare function qt3ts:environments(
  $map as map(*),
  $envs as element(environment)*,
  $file as map(*)
) as map(*) {
  map:new(
    ($map,
      for $env in $envs
      return if($env/@name)
        then map:entry($env/@name, qt3ts:environment($env, $file))
        else qt3ts:debug('Environment has no name', serialize($env))
    )
  )
};

declare function qt3ts:environment(
  $envs as element(environment),
  $file as map(*)
) as map(*)* {
  for $env in $envs/*
  let $name := xs:string($env/local-name())
  return switch($name)
    case 'source'
      return map:entry($name, map{
        'role' := $env/@role/string(),
        'file' := $file($env/@file/string()),
        'validation' := $env/@validation/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'namespace'
      return map:entry($name, map{
        'prefix' := $env/@prefix/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'collation'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'default' := $env/@default = 'true'
      })
    case 'collection'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'docs' := map:new((
          for $src in $env/source
          return map:entry($src/@file, map{
            'role' := $src/@role/string(),
            'file' := $file($src/@file/string()),
            'validation' := $src/@validation/string(),
            'uri' := xs:anyURI($src/@uri/string())
          })
        ))
      })
    case 'decimal-format'
      return map:entry($name, map:new((
        for $att in $env/@*
        return map:entry($att/name(), $att/string())
      )))
    case 'resource'
      return map:entry($name, map{
        'file' := $file($env/@file/string()),
        'media-type' := $env/@media-type/string(),
        'encoding' := $env/@encoding/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'schema'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'file' := $file($env/@file/string())
      })
    case 'static-base-uri'
      return map:entry($name, xs:anyURI($env/@uri/string()))
    case 'param'
      return map:entry($name, map{
        'name' := $env/@name/string(),
        'select' := $env/@select/string(),
        'as' := $env/@as/string(),
        'declared' := $env/@declared != 'false'
      })
    default
      return qt3ts:debug('Unknown environment parameter:', $env)
};

declare function qt3ts:get-files(
  $root as xs:string,
  $node as node()
)  as map(*) {
  map:new((
    let $root-len := string-length(file:path-to-native(substring($root, 9))) + 2,
        $uri := base-uri($node)
    for $file in $node//@file
    let $uri := replace($uri, '[^/]+$', $file)
    group by $path := replace(substring(
      file:path-to-native(substring($uri, 9)), $root-len), '\\', '/')
    return
      for $file in $file
      return map:entry($file, $path)
  ))
};

declare function qt3ts:insert-with(
  $combine as function(item()*, item()*) as item()*,
  $map as map(*),
  $key as item(),
  $value as item()*
) as map(*) {
  map:new(
    ( $map,
      map:entry(
        $key,
        if(map:contains($map, $key))
          then $combine(map:get($map, $key), $value)
          else $value
      )
    )
  )
};

declare function qt3ts:debug(
  $msg as xs:string,
  $itm as item()
) as empty-sequence() {
  trace($itm, $msg)[2]
};

(:~
 : Conversion module for creating JUnit tests from the QT3TS test suite.
 : @author Leo Woerteler
 : @version 0.1
 :)
module namespace qt3ts='http://www.basex.org/modules/qt3ts';

import module namespace qt3ts-java='http://www.basex.org/modules/qt3ts/java'
  at 'qt3ts-java.xqm';

declare default element namespace 'http://www.w3.org/2010/09/qt-fots-catalog';

(:~
 : Main entry point.
 : @param $path path to the test-suite
 : @param $test-sets to be converted
 : @param $package Java package
 : @param $out-path path for the generated Java files
 : @return nothing
 :)
declare function qt3ts:to-junit(
  $path as xs:string,
  $test-sets as xs:string*,
  $package as xs:string,
  $out-path as xs:string,
  $supports as function(xs:string, xs:string*) as xs:boolean
) as empty-sequence() {
  let $catalog := doc($path || $file:dir-separator || 'catalog.xml'),
      $root    := replace(base-uri($catalog), 'catalog\.xml$', ''),
      $files   := qt3ts:get-files($root, $catalog),
      $envs    := qt3ts:environments(map:new(), $catalog/catalog/environment, $files)
  let $files   :=
        qt3ts-java:test-suites(
          $package,
          map:new((
            for $test-set in
              if($test-sets = '*') then $catalog//test-set
              else
                for $name in $test-sets
                let $set := $catalog//test-set[@name = $name]
                return if($set) then $set else qt3ts:debug('Test-set not found', $name)
            return qt3ts:test-set($test-set, $root, $package, $supports, $envs)
          ))
        )
  for $name in map:keys($files)
  let $path := $out-path || $file:dir-separator || $name || '.java'
  return (
    file:create-dir(replace($path, '[^/\\]+$', '')),
    file:write($path, $files($name), map{ 'method' := 'text' })
  )
};

(:~
 : Processes a test-set.
 : @param $test-set the test-set element
 : @param $package Java package
 : @param $out-path path for the generated Java files
 : @return full class name
 :)
declare function qt3ts:test-set(
  $test-set as element(test-set),
  $root as xs:string,
  $package as xs:string,
  $supports as function(xs:string, xs:string*) as xs:boolean,
  $envs as map(*)
) as map(*)? {
  let $name := $test-set/@name/string(),
      $dir  := replace($test-set/@file, '/[^/]+$', ''),
      $path := $root || $test-set/@file,
      $doc  := doc($path),
      $file := qt3ts:get-files($root, $doc),
      $envs := qt3ts:environments($envs, $doc/test-set/environment, $file),
      $desc := if($doc/test-set/description)
                 then $doc/test-set/description/string()
                 else 'Test-set ' || $name || '.'
  let $tests := map:new((
    for $test-case in $doc/test-set/test-case
    where every $dep in $test-case/dependency
      satisfies $supports($dep/@type, tokenize($dep/@value, ' '))
    return map{ $test-case/@name := qt3ts:test-case($test-set, $test-case, $root, $envs, $file) }
  ))
  return if(map:size($tests) gt 0)
    then
      let $ts := qt3ts-java:test-set($package, $dir, $name, $desc, $tests)
      return if(contains($ts[2], ' void '))
        then map:entry($dir || '/' || $ts[1], $ts[2])
        else qt3ts:debug('Test-set skipped after serialization', $name)
    else qt3ts:debug('Test-set skipped', $name)
};

declare function qt3ts:test-case(
  $test-set as element(test-set),
  $test-case as element(test-case),
  $root as xs:string,
  $envs as map(*),
  $file as map(*)
) as map(*) {
  let $desc := $test-case/description/string(),
      $env := $test-case/environment,
      $mods := map:new((
          for $mod in $test-case/module
          return map:entry(
            xs:anyURI($mod/@uri/string()),
            $file($mod/@file)
          )
        )),
      $map :=
        if($env) then
          if($env/@ref) then
            if(map:contains($envs, $env/@ref))
              then $envs($env/@ref)
              else (
                qt3ts:debug('Couldn''t find environment',
                  $test-set/@name || ', ' || $env/@ref),
                map{}
              )
          else qt3ts:environment($env, $file)
        else map{},
      $test := if($test-case/test/@file)
        then qt3ts:read-test($test-set, $test-case)
        else $test-case/test/string(),
      $result := qt3ts:result($test-case/result/*, $file, $root)
  return map{
    'description' := $desc,
    'modules'     := $mods,
    'environment' := $map,
    'test'        := $test,
    'result'      := $result
  }
};

declare function qt3ts:result(
  $assert as element(),
  $file as map(*),
  $root as xs:string
) as map(*) {
  let $name := $assert/local-name()
  return map:entry($name,
    switch($name)
      case 'assert-true' return ()
      case 'assert-false' return ()
      case 'assert-empty' return ()
      case 'assert' return $assert/string()
      case 'assert-eq' return $assert/string()
      case 'assert-string-value' return map{
          'normalize-space' := $assert/@normalize-space = ('true', '1'),
          'result'          := $assert/string()
        }
      case 'assert-permutation' return $assert/string()
      case 'assert-type' return $assert/string()
      case 'assert-deep-eq' return $assert/string()
      case 'assert-count' return xs:integer($assert/string())
      case 'error' return $assert/@code/string()
      case 'assert-serialization-error' return $assert/@code/string()
      case 'assert-serialization' return map{
          'ignore-prefixes' := $assert/@ignore-prefixes = ('true', '1'),
          'result' := if($assert/@file)
            then
              let $path := $root || $file($assert/@file)
              return unparsed-text($path, 'UTF-8')
            else $assert/string()
        }
      case 'all-of' return map(qt3ts:result(?, $file, $root), $assert/*)
      case 'any-of' return map(qt3ts:result(?, $file, $root), $assert/*)
      default return qt3ts:debug('Unknown assertion', $name)
  )
};

declare function qt3ts:read-test(
  $test-set as element(test-set),
  $test-case as element(test-case)
) as xs:string {
  let $path := replace(base-uri($test-case), '[^/]+$', $test-case/test/@file)
  return unparsed-text($path, 'UTF-8')
};

declare function qt3ts:environments(
  $map as map(*),
  $envs as element(environment)*,
  $file as map(*)
) as map(*) {
  map:new(
    ($map,
      for $env in $envs
      return if($env/@name)
        then map:entry($env/@name, qt3ts:environment($env, $file))
        else qt3ts:debug('Environment has no name', serialize($env))
    )
  )
};

declare function qt3ts:environment(
  $envs as element(environment),
  $file as map(*)
) as map(*)* {
  for $env in $envs/*
  let $name := xs:string($env/local-name())
  return switch($name)
    case 'source'
      return map:entry($name, map{
        'role' := $env/@role/string(),
        'file' := $file($env/@file/string()),
        'validation' := $env/@validation/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'namespace'
      return map:entry($name, map{
        'prefix' := $env/@prefix/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'collation'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'default' := $env/@default = 'true'
      })
    case 'collection'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'docs' := map:new((
          for $src in $env/source
          return map:entry($src/@file, map{
            'role' := $src/@role/string(),
            'file' := $file($src/@file/string()),
            'validation' := $src/@validation/string(),
            'uri' := xs:anyURI($src/@uri/string())
          })
        ))
      })
    case 'decimal-format'
      return map:entry($name, map:new((
        for $att in $env/@*
        return map:entry($att/name(), $att/string())
      )))
    case 'resource'
      return map:entry($name, map{
        'file' := $file($env/@file/string()),
        'media-type' := $env/@media-type/string(),
        'encoding' := $env/@encoding/string(),
        'uri' := xs:anyURI($env/@uri/string())
      })
    case 'schema'
      return map:entry($name, map{
        'uri' := xs:anyURI($env/@uri/string()),
        'file' := $file($env/@file/string())
      })
    case 'static-base-uri'
      return map:entry($name, xs:anyURI($env/@uri/string()))
    case 'param'
      return map:entry($name, map{
        'name' := $env/@name/string(),
        'select' := $env/@select/string(),
        'as' := $env/@as/string(),
        'declared' := $env/@declared != 'false'
      })
    default
      return qt3ts:debug('Unknown environment parameter:', $env)
};

declare function qt3ts:get-files(
  $root as xs:string,
  $node as node()
)  as map(*) {
  map:new((
    let $root-len := string-length(file:path-to-native(substring($root, 9))) + 2,
        $uri := base-uri($node)
    for $file in $node//@file
    let $uri := replace($uri, '[^/]+$', $file)
    group by $path := replace(substring(
      file:path-to-native(substring($uri, 9)), $root-len), '\\', '/')
    return
      for $file in $file
      return map:entry($file, $path)
  ))
};

declare function qt3ts:insert-with(
  $combine as function(item()*, item()*) as item()*,
  $map as map(*),
  $key as item(),
  $value as item()*
) as map(*) {
  map:new(
    ( $map,
      map:entry(
        $key,
        if(map:contains($map, $key))
          then $combine(map:get($map, $key), $value)
          else $value
      )
    )
  )
};

declare function qt3ts:debug(
  $msg as xs:string,
  $itm as item()
) as empty-sequence() {
  trace($itm, $msg)[2]
};


removed debugging message

removed debugging message

import module namespace csd = "urn:ihe:iti:csd:2013" at "../repo/csd_base_library.xqm";
import module namespace csd_blu = "https://github.com/his-interop/openinfoman/csd_blu" at "../repo/csd_base_library_updating.xqm";
declare default element  namespace   "urn:ihe:iti:csd:2013";
declare variable $careServicesRequest as item() external;

(:
   The query will be executed against the root element of the CSD document.

   The dynamic context of this query has $careServicesRequest set to contain any of the search
   and limit paramaters as sent by the Service Finder
:)

let $provs0 := if (exists($careServicesRequest/id/@oid)) then	csd:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingSchema) ) then $provs1  else ()
let $cred_new := $careServicesRequest/credential
let $code:= $cred_new/codedType/@code
let $codingSchema:= $cred_new/codedType/@codingSchema
let $creds0 := $provs2/credential/codedType[@code = $code and @codingSchema = $codingSchema]
return
  if ( count($provs2) = 1 and count($creds0) = 1)  (:Update only:)
    then
    let $cred_old := $creds0[1]/..
    let $provider:= $provs2[1]
    let $provs3 :=
      <provider oid="{$provider/@oid}">
	<credential>
	  <codedType code="{$code}" codingSchema="{$codingSchema}"/>
	</credential>
      </provider>

    return

      (
	csd_blu:bump_timestamp($provider),
	if (exists($cred_new/issuingAuthority)) then
	  (if (exists($cred_old/issuingAuthority)) then (delete node $cred_old/issuingAuthority) else (),
	  insert node $cred_new/issuingAuthority into $cred_old)
	else (),
	if (exists($cred_new/number)) then
	  (if (exists($cred_old/number)) then (delete node $cred_old/number) else (),
	  insert node $cred_new/number into $cred_old)
	else (),
	if (exists($cred_new/credentialIssueDate)) then
	  (if (exists($cred_old/credentialIssueDate)) then (delete node $cred_old/credentialIssueDate) else (),
	  insert node $cred_new/credentialIssueDate into $cred_old)
	else (),
	if (exists($cred_new/credentialRenewalDate)) then
	  (if (exists($cred_old/credentialRenewalDate)) then (delete node $cred_old/credentialRenewalDate) else (),
	  insert node $cred_new/credentialRenewalDate into $cred_old)
	else (),
	csd_blu:wrap_updating_providers($provs3)
       )
  else 	csd_blu:wrap_updating_providers(())

import module namespace csd = "urn:ihe:iti:csd:2013" at "../repo/csd_base_library.xqm";
import module namespace csd_blu = "https://github.com/his-interop/openinfoman/csd_blu" at "../repo/csd_base_library_updating.xqm";
declare default element  namespace   "urn:ihe:iti:csd:2013";
declare variable $careServicesRequest as item() external;

(:
   The query will be executed against the root element of the CSD document.

   The dynamic context of this query has $careServicesRequest set to contain any of the search
   and limit paramaters as sent by the Service Finder
:)

let $provs0 := if (exists($careServicesRequest/id/@oid)) then	csd:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingSchema) ) then $provs1  else ()
let $cred_new := $careServicesRequest/credential
let $code:= $cred_new/codedType/@code
let $codingSchema:= $cred_new/codedType/@codingSchema
let $creds0 := $provs2/credential/codedType[@code = $code and @codingSchema = $codingSchema]
return
  if ( count($provs2) = 1 and count($creds0) = 1)  (:Update only:)
    then
    let $cred_old := $creds0[1]/..
    let $provider:= $provs2[1]
    let $provs3 :=
      <provider oid="{$provider/@oid}">
	<credential>
	  <codedType code="{$code}" codingSchema="{$codingSchema}"/>
	</credential>
      </provider>

    return

      (
	csd_blu:bump_timestamp($provider),
	if (exists($cred_new/issuingAuthority)) then
	  (if (exists($cred_old/issuingAuthority)) then (delete node $cred_old/issuingAuthority) else (),
	  insert node $cred_new/issuingAuthority into $cred_old)
	else (),
	if (exists($cred_new/number)) then
	  (if (exists($cred_old/number)) then (delete node $cred_old/number) else (),
	  insert node $cred_new/number into $cred_old)
	else (),
	if (exists($cred_new/credentialIssueDate)) then
	  (if (exists($cred_old/credentialIssueDate)) then (delete node $cred_old/credentialIssueDate) else (),
	  insert node $cred_new/credentialIssueDate into $cred_old)
	else (),
	if (exists($cred_new/credentialRenewalDate)) then
	  (if (exists($cred_old/credentialRenewalDate)) then (delete node $cred_old/credentialRenewalDate) else (),
	  insert node $cred_new/credentialRenewalDate into $cred_old)
	else (),
	csd_blu:wrap_updating_providers($provs3)
       )
  else 	csd_blu:wrap_updating_providers((<bad cs="{$codingSchema}" c="{$code}"></bad>,count($provs2), count($creds0)))


EXPath File Module 1.0 (20150220) function definitions.

xquery version "3.0";
(:~
 : File Module 1.0 (EXPath Module 20 February 2015)
 :
 : @see http://expath.org/spec/file/1.0
 : @see http://docs.basex.org/wiki/File_Module
 :)
module namespace file = "http://expath.org/ns/file";

declare namespace a = "http://reecedunn.co.uk/xquery/annotations";
declare namespace o = "http://reecedunn.co.uk/xquery/options";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option o:requires "expath-file/1.0-20100517";

declare option o:implements-module "basex/7.0 as expath-file/1.0-20100517"; (: NOTE: 7.0 is the earliest version definitions are available for. :)
declare option o:implements-module "basex/7.3 as expath-file/1.0-20120614";
declare option o:implements-module "basex/7.8 as expath-file/1.0-20131203";
declare option o:implements-module "basex/8.0 as expath-file/1.0-20150220";

declare type append-params = (
    %a:since("expath-file", "1.0-20120614") for element(output:serialization-parameters) |
    %a:since("basex", "7.0") for item()
);

declare type copy-write-result = (
    %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") for xs:boolean |
    %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") for empty-sequence()
);

declare type path-uri-result = (
    %a:since("expath-file", "1.0-20100517") for xs:anyURI |
    %a:since("basex", "7.0") for xs:string
);

declare type write-params = (
    %a:since("expath-file", "1.0-20100517") for node()* |
    %a:since("basex", "7.0") for item()
);

declare type any-binary-type = (
    %a:since("expath-file", "1.0-20120614") for xs:base64Binary |
    %a:since("basex", "7.0") for (xs:base64Binary | xs:hexBinary)
);

declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:dir-separator#0") variable $file:directory-separator external;
declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:path-separator#0") variable $file:path-separator external;

declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append($path as xs:string, $items as item()*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append($path as xs:string, $items as item()*, $params as append-params) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append-binary($path as xs:string, $value as any-binary-type) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text($path as xs:string, $value as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text($path as xs:string, $value as xs:string, $encoding as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text-lines($path as xs:string, $values as xs:string*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text-lines($path as xs:string, $values as xs:string*, $encoding as xs:string) as empty-sequence() external;
declare %a:until("expath-file", "1.0-20150220") function file:base-dir() as xs:string? external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:since("expath-file", "1.0-20131203", "file:name#1") %a:until("basex", "7.8", "file:name#1") function file:base-name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:since("expath-file", "1.0-20131203") %a:until("basex", "7.8") function file:base-name($path as xs:string, $suffix as xs:string) as xs:string external;
declare %a:until("expath-file", "1.0-20150220") function file:children($dir as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") function file:copy($source as xs:string, $destination as xs:string) as copy-write-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:copy($source as xs:string, $destination as xs:string, $overwrite as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") function file:create-dir($dir as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:create-dir#1") function file:create-directory($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-dir($prefix as xs:string, $suffix as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-dir($prefix as xs:string, $suffix as xs:string, $dir as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-file($prefix as xs:string, $suffix as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-file($prefix as xs:string, $suffix as xs:string, $dir as xs:string) as xs:string external;
declare %a:until("expath-file", "1.0-20150220") function file:current-dir() as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:delete($path as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.2.1") function file:delete($path as xs:string, $recursive as xs:boolean) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:until("expath-file", "1.0-20131203", "file:parent#1") %a:until("basex", "7.8", "file:parent#1") function file:dir-name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:dir-separator() as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:exists($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string, $pattern as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string, $pattern as xs:string, $recursive as xs:boolean) as xs:string* external;
declare %a:since("basex", "8.2") function file:is-absolute($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") function file:is-dir($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:since("basex", "7.0") %a:until("expath-file", "1.0-20120614", "file:is-dir#1") %a:until("basex", "7.3", "file:is-dir#1") function file:is-directory($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") function file:is-file($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") function file:last-modified($path as xs:string) as xs:dateTime external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.3") function file:line-separator() as xs:string external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string) as xs:string* external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string, $recursive as xs:boolean) as xs:string* external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdir($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdir($dir as xs:string, $create as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdirs($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdirs($dir as xs:string, $create as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:move($source as xs:string, $target as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20131203") function file:name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") function file:parent($path as xs:string) as xs:string? external;
declare %a:since("expath-file", "1.0-20100517") function file:path-separator() as xs:string external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614", "file:path-to-native#1") function file:path-to-full-path($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:path-to-native($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:path-to-uri($path as xs:string) as path-uri-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614", "file:read-binary#1") function file:read($file as xs:string) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-binary($path as xs:string) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20131203") function file:read-binary($path as xs:string, $offset as xs:integer) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20131203") function file:read-binary($path as xs:string, $offset as xs:integer, $length as xs:integer) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") function file:read-html($file as xs:string, $tidyOptions as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:read-text($file as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text($path as xs:string, $encoding as xs:string) as xs:string external;
declare %a:since("basex", "8.5") function file:read-text($path as xs:string, $encoding as xs:string, $fallback as xs:boolean) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text-lines($path as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text-lines($path as xs:string, $encoding as xs:string) as xs:string* external;
declare %a:since("basex", "8.5") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean) as xs:string* external;
declare %a:since("basex", "9.0") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer) as xs:string* external;
declare %a:since("basex", "9.0") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer, $length as xs:integer) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:read-xml($file as xs:string) as node() external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:read-xml($file as xs:string, $tidy as xs:boolean) as node() external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:remove($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "8.2") function file:resolve-path($path as xs:string) as xs:string external;
declare %a:since("basex", "8.2") function file:resolve-path($path as xs:string, $base as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:size($file as xs:string) as xs:integer external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:temp-dir() as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:write($path as xs:string, $items as item()*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20100517") function file:write($file as xs:string, $content as item()*, $params as write-params) as copy-write-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:write($file as xs:string, $content as item()*, $params as node()*, $append as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:write-binary($path as xs:string, $value as any-binary-type) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20131203") function file:write-binary($path as xs:string, $value as any-binary-type, $offset as xs:integer) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text($path as xs:string, $value as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text($path as xs:string, $value as xs:string, $encoding as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text-lines($path as xs:string, $values as xs:string*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text-lines($path as xs:string, $values as xs:string*, $encoding as xs:string) as empty-sequence() external;

xquery version "3.0";
(:~
 : File Module 1.0 (EXPath Module 20 February 2015)
 :
 : @see http://expath.org/spec/file/1.0
 : @see http://docs.basex.org/wiki/File_Module
 :)
module namespace file = "http://expath.org/ns/file";

declare namespace a = "http://reecedunn.co.uk/xquery/annotations";
declare namespace o = "http://reecedunn.co.uk/xquery/options";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";

declare option o:requires "expath-file/1.0-20100517";

declare option o:implements-module "basex/7.0 as expath-file/1.0-20100517"; (: NOTE: 7.0 is the earliest version definitions are available for. :)
declare option o:implements-module "basex/7.3 as expath-file/1.0-20120614";
declare option o:implements-module "basex/7.8 as expath-file/1.0-20131203";

declare type append-params = (
    %a:since("expath-file", "1.0-20120614") for element(output:serialization-parameters) |
    %a:since("basex", "7.0") for item()
);

declare type copy-write-result = (
    %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") for xs:boolean |
    %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") for empty-sequence()
);

declare type path-uri-result = (
    %a:since("expath-file", "1.0-20100517") for xs:anyURI |
    %a:since("basex", "7.0") for xs:string
);

declare type write-params = (
    %a:since("expath-file", "1.0-20100517") for node()* |
    %a:since("basex", "7.0") for item()
);

declare type any-binary-type = (
    %a:since("expath-file", "1.0-20120614") for xs:base64Binary |
    %a:since("basex", "7.0") for (xs:base64Binary | xs:hexBinary)
);

declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:dir-separator#0") variable $file:directory-separator external;
declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:path-separator#0") variable $file:path-separator external;

declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append($path as xs:string, $items as item()*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append($path as xs:string, $items as item()*, $params as append-params) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:append-binary($path as xs:string, $value as any-binary-type) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text($path as xs:string, $value as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text($path as xs:string, $value as xs:string, $encoding as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text-lines($path as xs:string, $values as xs:string*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:append-text-lines($path as xs:string, $values as xs:string*, $encoding as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:since("expath-file", "1.0-20131203", "file:name#1") %a:until("basex", "7.8", "file:name#1") function file:base-name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:since("expath-file", "1.0-20131203") %a:until("basex", "7.8") function file:base-name($path as xs:string, $suffix as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:copy($source as xs:string, $destination as xs:string) as copy-write-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:copy($source as xs:string, $destination as xs:string, $overwrite as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") function file:create-dir($dir as xs:string) as empty-sequence() external;
declare %a:since("basex", "7.0") %a:until("basex", "7.3", "file:create-dir#1") function file:create-directory($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-dir($prefix as xs:string, $suffix as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-dir($prefix as xs:string, $suffix as xs:string, $dir as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-file($prefix as xs:string, $suffix as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:create-temp-file($prefix as xs:string, $suffix as xs:string, $dir as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:delete($path as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.2.1") function file:delete($path as xs:string, $recursive as xs:boolean) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") %a:until("expath-file", "1.0-20131203", "file:parent#1") %a:until("basex", "7.8", "file:parent#1") function file:dir-name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:dir-separator() as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:exists($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string, $pattern as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:files($path as xs:string, $pattern as xs:string, $recursive as xs:boolean) as xs:string* external;
declare %a:since("expath-file", "1.0-20120614") function file:is-dir($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:since("basex", "7.0") %a:until("expath-file", "1.0-20120614", "file:is-dir#1") %a:until("basex", "7.3", "file:is-dir#1") function file:is-directory($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") function file:is-file($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") function file:last-modified($path as xs:string) as xs:dateTime external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.3") function file:line-separator() as xs:string external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string) as xs:string* external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string, $recursive as xs:boolean) as xs:string* external;
declare %a:until("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:list($dir as xs:string, $recursive as xs:boolean, $pattern as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdir($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdir($dir as xs:string, $create as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdirs($dir as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:mkdirs($dir as xs:string, $create as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:move($source as xs:string, $target as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20131203") function file:name($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20131203") function file:parent($path as xs:string) as xs:string? external;
declare %a:since("expath-file", "1.0-20100517") function file:path-separator() as xs:string external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614", "file:path-to-native#1") function file:path-to-full-path($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:path-to-native($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:path-to-uri($path as xs:string) as path-uri-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614", "file:read-binary#1") function file:read($file as xs:string) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-binary($path as xs:string) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20131203") function file:read-binary($path as xs:string, $offset as xs:integer) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20131203") function file:read-binary($path as xs:string, $offset as xs:integer, $length as xs:integer) as xs:base64Binary external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") function file:read-html($file as xs:string, $tidyOptions as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20100517") function file:read-text($file as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text($path as xs:string, $encoding as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text-lines($path as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:read-text-lines($path as xs:string, $encoding as xs:string) as xs:string* external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:read-xml($file as xs:string) as node() external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:read-xml($file as xs:string, $tidy as xs:boolean) as node() external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:remove($path as xs:string) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "8.2") function file:resolve-path($path as xs:string) as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:size($file as xs:string) as xs:integer external;
declare %a:since("expath-file", "1.0-20131203") %a:since("basex", "7.7") function file:temp-dir() as xs:string external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:write($path as xs:string, $items as item()*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20100517") function file:write($file as xs:string, $content as item()*, $params as write-params) as copy-write-result external;
declare %a:since("expath-file", "1.0-20100517") %a:until("expath-file", "1.0-20120614") %a:missing("basex", "7.0") function file:write($file as xs:string, $content as item()*, $params as node()*, $append as xs:boolean) as xs:boolean external;
declare %a:since("expath-file", "1.0-20120614") %a:since("basex", "7.0") function file:write-binary($path as xs:string, $value as any-binary-type) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20131203") function file:write-binary($path as xs:string, $value as any-binary-type, $offset as xs:integer) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text($path as xs:string, $value as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text($path as xs:string, $value as xs:string, $encoding as xs:string) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text-lines($path as xs:string, $values as xs:string*) as empty-sequence() external;
declare %a:since("expath-file", "1.0-20120614") function file:write-text-lines($path as xs:string, $values as xs:string*, $encoding as xs:string) as empty-sequence() external;

declare %a:since("basex", "8.0") function file:children($dir as xs:string) as xs:string* external;
declare %a:since("basex", "8.5") function file:read-text($path as xs:string, $encoding as xs:string, $fallback as xs:boolean) as xs:string external;
declare %a:since("basex", "8.5") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean) as xs:string* external;
declare %a:since("basex", "9.0") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer) as xs:string* external;
declare %a:since("basex", "9.0") function file:read-text-lines($path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer, $length as xs:integer) as xs:string* external;
declare %a:since("basex", "8.2") function file:is-absolute($path as xs:string) as xs:boolean external;
declare %a:since("basex", "8.2") function file:resolve-path($path as xs:string, $base as xs:string) as xs:string external;
declare %a:since("basex", "8.0") function file:current-dir() as xs:string external;
declare %a:since("basex", "8.0") function file:base-dir() as xs:string? external;


simplified stored function processor

simplified stored function processor

(:~
: This is the Care Services Discovery RESTful document processor
: @version 1.0
: @see https://github.com/his-interop/openinfoman
:
:)
module namespace csd_proc = "https://github.com/his-interop/openinfoman";

declare   namespace   csd = "urn:ihe:iti:csd:2013";
declare default element  namespace   "urn:ihe:iti:csd:2013";

declare function csd_proc:process_CSR($careServicesRequest, $doc)
{

if ($careServicesRequest/function)
then
  csd_proc:process_CSR_stored($careServicesRequest/csd:function,$doc)
else if ($careServicesRequest/expression)
then
  csd_proc:process_CSR_adhoc($careServicesRequest/expression,$doc)
else
  <rest:response>
    <http:response status="400" message="Invalid care services request.">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
  </rest:response>

};

declare function csd_proc:process_CSR_adhoc($expression,$doc) as element()
{
  <rest:response>
    <http:response status="404" message="Ad-Hoc not imeplemented yet.">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
  </rest:response>

};

declare function csd_proc:lookup_stored($uuid)
{

let $stored_functions :=
<storedFunctions>
   <function uuid='4e8bbeb9-f5f5-11e2-b778-0800200c9a66'
   	     method='csd_proc:process_CSR_provider_search'
 	     content-type='text/xml; charset=utf-8'
	     />
</storedFunctions>

return $stored_functions/function[@uuid = $uuid]

};

declare function csd_proc:process_CSR_stored($function,$doc)
{
let $stored := csd_proc:lookup_stored($function/@uuid)
let $method := if ($stored) then function-lookup( xs:QName(text{$stored/@method}), 2) else ()
return if (exists($method ))
  then
      let $result :=  $method($function/requestParams,$doc)
       return if ($function/@encapsulated)
       then
          csd_proc:wrap_result($result,$stored/@content-type)
       else
	 (<rest:response>
	   <http:response status="200" >
	     <http:header name="Content-Type" value="{$stored/@content-type}"/>
	   </http:response>
	 </rest:response>,
	 $result
	 )
  else
    <rest:response>
     <http:response status="404" message="No registered function with UUID='{$function/@uuid}.'">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
     </http:response>
    </rest:response>

};

declare function csd_proc:wrap_result($result,$content-type) {
 <careServicesResponse content-type="{$content-type}"><result>{$result}</result></careServicesResponse>
};

declare function csd_proc:process_CSR_provider_search($careServicesRequest, $doc) as element()
{
<CSD xmlns:csd="urn:ihe:iti:csd:2013"  >
  <organizationDirectory/>
  <serviceDirectory/>
  <facilityDirectory/>
  <providerDirectory>
    {

      let $provs0 := csd:filter_by_primary_id($doc/CSD/providerDirectory/*,$careServicesRequest/id)

      let $provs1 := csd:filter_by_other_id($provs0,$careServicesRequest/otherID)

      let $provs2 := csd:filter_by_common_name($provs1,$careServicesRequest/commonName)

      let $provs3 := csd:filter_by_coded_type($provs2,$careServicesRequest/type)

      let $provs4 := csd:filter_by_address($provs3, $careServicesRequest/address/addressLine)

      let $provs5 :=  csd:filter_by_record($provs4,$careServicesRequest/record)

      return csd:limit_items($provs5,$careServicesRequest/start,$careServicesRequest/max)

    }
  </providerDirectory>
</CSD>

};

(:~
: This is the Care Services Discovery RESTful document processor
: @version 1.0
: @see https://github.com/his-interop/openinfoman
:
:)
module namespace csd_proc = "https://github.com/his-interop/openinfoman";

declare   namespace   csd = "urn:ihe:iti:csd:2013";
declare default element  namespace   "urn:ihe:iti:csd:2013";

declare function csd_proc:process_CSR($careServicesRequest, $doc)
{

if ($careServicesRequest/function)
then
  csd_proc:process_CSR_stored($careServicesRequest/csd:function,$doc)
else if ($careServicesRequest/expression)
then
  csd_proc:process_CSR_adhoc($careServicesRequest/expression,$doc)
else
  <rest:response>
    <http:response status="400" message="Invalid care services request.">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
  </rest:response>

};

declare function csd_proc:process_CSR_adhoc($expression,$doc) as element()
{
  <rest:response>
    <http:response status="404" message="Ad-Hoc not imeplemented yet.">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
    </http:response>
  </rest:response>

};

declare function csd_proc:lookup_stored($uuid)
{

let $stored_functions :=
<storedFunctions>
   <function uuid='4e8bbeb9-f5f5-11e2-b778-0800200c9a66'
   	     method='csd_proc:process_CSR_provider_search'
 	     content-type='text/xml; charset=utf-8'
	     />
</storedFunctions>

return $stored_functions/function[@uuid = $uuid]

};

declare function csd_proc:process_CSR_stored($function,$doc)
{
let $stored := csd_proc:lookup_stored($function/@uuid)
return if ($stored)
then
  let $method := function-lookup( xs:QName(text{$stored/@method}), 2)
  return if (exists($method ))
  then
      let $result :=  $method($function/requestParams,$doc)
       return if ($function/@encapsulated)
       then
          csd_proc:wrap_result($result,$stored/@content-type)
       else
	 (<rest:response>
	   <http:response status="200" >
	     <http:header name="Content-Type" value="{$stored/@content-type}"/>
	   </http:response>
	 </rest:response>,
	 $result
	 )
  else
    <rest:response>
     <http:response status="404" message="No registered function with UUID='{$function/@uuid}.'">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
     </http:response>
    </rest:response>
else
    <rest:response>
     <http:response status="404" message="No registered function with UUID='{$function/@uuid}.'">
      <http:header name="Content-Language" value="en"/>
      <http:header name="Content-Type" value="text/html; charset=utf-8"/>
     </http:response>
    </rest:response>

};

declare function csd_proc:wrap_result($result,$content-type) {
 <careServicesResponse content-type="{$content-type}"><result>{$result}</result></careServicesResponse>
};

declare function csd_proc:process_CSR_provider_search($careServicesRequest, $doc) as element()
{
<CSD xmlns:csd="urn:ihe:iti:csd:2013"  >
  <organizationDirectory/>
  <serviceDirectory/>
  <facilityDirectory/>
  <providerDirectory>
    {

      let $provs0 := csd:filter_by_primary_id($doc/CSD/providerDirectory/*,$careServicesRequest/id)

      let $provs1 := csd:filter_by_other_id($provs0,$careServicesRequest/otherID)

      let $provs2 := csd:filter_by_common_name($provs1,$careServicesRequest/commonName)

      let $provs3 := csd:filter_by_coded_type($provs2,$careServicesRequest/type)

      let $provs4 := csd:filter_by_address($provs3, $careServicesRequest/address/addressLine)

      let $provs5 :=  csd:filter_by_record($provs4,$careServicesRequest/record)

      return csd:limit_items($provs5,$careServicesRequest/start,$careServicesRequest/max)

    }
  </providerDirectory>
</CSD>

};


updated XQuery submission script

updated XQuery submission script

(: Schema for results :)
import schema default element namespace "http://www.w3.org/2005/02/query-test-XQTSResult" at "w3c_reportingresults/XQTSResult.xsd";

(: Test.xml file from ctest :)
declare variable $ctests as document-node() external;

if(fn:empty($ctests)) then
  fn:error()
else
  validate {
    <test-suite-result>
       <implementation name="Zorba"
         version='1.0.0 (svn rev. 8152)'
         anonymous-result-column="false">

         <organization
            name='FLWOR Foundation'
            website="http://zorba-xquery.com/"
            anonymous="false" />

         <submittor
            name="Zorba Team"
            email="contact@zorba-xquery.com" />

         <description>

Zorba is a general purpose XQuery processor implementing in C++
            the W3C family of specifications. It is not an XML database.
            The query processor has been designed to be embeddable in a
            variety of environments such as other programming languages
            extended with XML processing capabilities, browsers,
            database servers, XML message dispatchers, or smartphones.
            Its architecture employes a modular design, which allows customizing
            the Zorba query processor to the environment’s needs.
            In particular the architecture of the query processor allows a
            pluggable XML store (e.g. main memory, DOM stores, persistent
            disk-based large stores, S3 stores). Zorba runs on most platforms
            and is available under the Apache license v2. Currently, Zorba
            implements the following W3C specifications: XQuery 1.0, XQuery Update
            Facility 1.0, XQuery Scripting Extension 1.0, and XSLT 2.0 and XQuery 1.0
            Serialization.

         </description>

         <implementation-defined-items>
           <implementation-defined-item
              name="The revalidation modes that are supported by this implementation."
              value="lax, skip, strict" />

          <implementation-defined-item
             name="The default revalidation mode for this implementation."
             value="lax" />

         </implementation-defined-items>

         <features>
            <feature name='Minimum Conformance' supported='true' />
            <feature name='Schema Import Feature' supported='true' />
            <feature name='Schema Validation Feature' supported='true' />
            <feature name='Static Typing Feature' supported='true' />
            <feature name='Full Axis Feature' supported='true' />
            <feature name='Module Feature' supported='true' />
            <feature name='Serialization Feature' supported='true' />
         </features>

         <context-properties>
            <context-property name="Boundary-space policy" context-type="static" value="strip"/>
            <context-property name="Ordering mode" context-type="static" value="ordered"/>
            <context-property name="Context item static type" context-type="static" value="item()"/>
            <context-property name="Default element/type namespace" context-type="static" value=""/>
            <context-property name="Default function namespace" context-type="static" value="http://www.w3.org/2005/xpath-functions"/>

            <context-property name="Default collation" context-type="static" value="http://www.w3.org/2005/xpath-functions/collation/codepoint"/>
            <context-property name="Construction mode" context-type="static" value="preserve"/>

            <context-property name="Default order for empty sequences" context-type="static" value="empty greatest"/>

            <context-property name="Copy-namespaces mode" context-type="static" value="inherit preserve"/>

         </context-properties>

       </implementation>

       <syntax>XQuery</syntax>

       <test-run dateRun="2010-04-28">
          <test-suite version="1.0.2"/>
          <transformation>
Standard
</transformation>
          <comparison>
Standard
</comparison>
          <otherComments>
None
</otherComments>
       </test-run>

       {
         for $test in $ctests/*:Site/*:Testing/*:Test
         let $testname := fn:tokenize(fn:data($test/*:Name), "/")[last()]
         return
           <test-case
             name="{$testname}"
             result="{fn:substring(fn:data($test/@Status), 0, 5)}"
           />
       }
    </test-suite-result>
  }

(: Schema for results :)
import schema default element namespace "http://www.w3.org/2005/02/query-test-XQTSResult" at "w3c_reportingresults/XQTSResult.xsd";

(: Test.xml file from ctest :)
declare variable $ctests as document-node() external;

if(fn:empty($ctests)) then
  fn:error()
else
  validate {
    <test-suite-result>
       <implementation name="Zorba"
         version='1.0.0 (svn rev. 7923)'
         anonymous-result-column="false">

         <organization
            name='FLWOR Foundation'
            website="http://zorba-xquery.com/"
            anonymous="false" />

         <submittor
            name="Zorba Team"
            email="contact@zorba-xquery.com" />

         <description>

Zorba is a general purpose XQuery processor implementing in C++
            the W3C family of specifications. It is not an XML database.
            The query processor has been designed to be embeddable in a
            variety of environments such as other programming languages
            extended with XML processing capabilities, browsers,
            database servers, XML message dispatchers, or smartphones.
            Its architecture employes a modular design, which allows customizing
            the Zorba query processor to the environment’s needs.
            In particular the architecture of the query processor allows a
            pluggable XML store (e.g. main memory, DOM stores, persistent
            disk-based large stores, S3 stores). Zorba runs on most platforms
            and is available under the Apache license v2. Currently, Zorba
            implements the following W3C specifications: XQuery 1.0, XQuery Update
            Facility 1.0, XQuery Scripting Extension 1.0, and XSLT 2.0 and XQuery 1.0
            Serialization.

         </description>

         <implementation-defined-items>
           <implementation-defined-item
              name="The revalidation modes that are supported by this implementation."
              value="lax, skip, strict" />

          <implementation-defined-item
             name="The default revalidation mode for this implementation."
             value="lax" />

         </implementation-defined-items>

         <features>
            <feature name='Minimum Conformance' supported='true' />
            <feature name="Full Axis Feature" supported='true' />
         </features>

         <context-properties>
           <context-property
             name="Revalidation mode"
             value="lax"
             context-type="static"/>
         </context-properties>

       </implementation>

       <syntax>XQuery</syntax>

       <test-run dateRun="2010-03-02">
          <test-suite version="1.0.6"/>
          <transformation>
Standard
</transformation>
          <comparison>
Standard
</comparison>
          <otherComments>
None
</otherComments>
       </test-run>

       {
         for $test in $ctests/*:Site/*:Testing/*:Test
         let $testname := fn:tokenize(fn:data($test/*:Name), "/")[last()]
         return
           <test-case
             name="{$testname}"
             result="{fn:substring(fn:data($test/@Status), 0, 5)}"
           />
       }
    </test-suite-result>
  }


Added case-insensitivity and space handling within search parameters

import module namespace notes="http://cefn.com/readinglog/notes" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/notes.xq";
import module namespace template="http://cefn.com/readinglog/template" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/template.xq";
declare default element namespace "http://www.w3.org/1999/xhtml";

declare variable $text external;

(: Defines the set of text nodes matching the requested string:)
let $match := replace($text,'\+',' '),
	$needles := notes:allnotes()//text()[matches(.,$match,'i')],
	$types := distinct-values(for $item in $needles return notes:gettype($item))
return

(: TODO CH refactor to use grouping logic demostrated in authors.xq if possible,
	to minimise complexity and separate querying from templating:)
template:webpage(

Search: "{$match}" ({count($needles)} matches)

		{
			for $note in $needles/root() return (

						{$note//h1/string(.)}
						{notes:paperlinks($note)}

,
				for $type in distinct-values($needles[root()=$note]/notes:gettype(.)) order by notes:typepriority($type) return(

{$type}

						{
							for $needle in $needles[notes:gettype(.)=$type][root()=$note] return

									{$needle}

						}

				)
			)
		}

)

import module namespace notes="http://cefn.com/readinglog/notes" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/notes.xq";
import module namespace template="http://cefn.com/readinglog/template" at "/home/cefn/Documents/highwire/participatory firmware design/readinglog/scripts/server/xquery/lib/template.xq";
declare default element namespace "http://www.w3.org/1999/xhtml";

declare variable $text external;

(: Defines the set of text nodes matching the requested string:)
declare variable $needles := $notes:allnotes//text()[contains(.,$text)];
declare variable $types := distinct-values(for $item in $needles return notes:type($item));

template:webpage(

Search: {$text} ({count($needles)} matches)

		{
			for $note in $needles/root() return (

						{$note//h1/string(.)}
						{notes:paperlinks($note)}

,
				for $type in distinct-values($needles[root()=$note]/notes:type(.)) order by notes:typepriority($type) return(

{$type}

						{
							for $needle in $needles[notes:type(.)=$type][root()=$note] return

									{$needle}

						}

				)
			)
		}

)


minor formatting changes

minor formatting changes

xquery version "1.0";

(: ~
 : Module Name:             new property webpage and XQuery
 :
 : Module Version           2.0
 :
 : Date                     31st July 2007
 :
 : Copyright                The cagrid consortium
 :
 : Module overview          Creates and property and displays list
 :
 :)

(:~
 :    @author Steve Harris
 :    @version 0.1
 :
 :    @author Steve Harris
 :    @version 2.0
 :     now allows searching for concept terms
~ :)

  import module namespace
  lib-forms="http://www.cagrid.org/xquery/library/forms"
  at "../edit/m-lib-forms.xquery";

  import module namespace
  lib-util="http://www.cagrid.org/xquery/library/util"
  at "../library/m-lib-util.xquery";

  import module namespace
  lib-rendering="http://www.cagrid.org/xquery/library/rendering"
  at "../web/m-lib-rendering.xquery";

  import module namespace
    lib-make-admin-item="http://www.cagrid.org/xquery/library/make-admin-item"
    at "../edit/m-lib-make-admin-item.xquery";

declare namespace openMDR = "http://www.cagrid.org/schema/openMDR";
declare namespace ISO11179= "http://www.cagrid.org/schema/ISO11179";
declare namespace session="http://exist-db.org/xquery/session";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace exist = "http://exist.sourceforge.net/NS/exist";

declare function local:property(
   $reg-auth as xs:string,
   $administrative-note as xs:string,
   $administrative-status as xs:string,
   $administered-by as xs:string,
   $submitted-by as xs:string,
   $registered-by as xs:string,
   $context-ids as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $uri as xs:string?,
   $preferred as xs:string?
   ) as xs:boolean
{
   let $version := '0.1'
   let $data-identifier := lib-forms:generate-id()
   let $new-identifier := concat($reg-auth, '-', $data-identifier, '-', $version)
   let $doc-name := concat($new-identifier,'.xml')

   let $content := (
            lib-make-admin-item:administration-record($administrative-note,$administrative-status,'Recorded'),
            lib-make-admin-item:custodians($administered-by,$registered-by,$submitted-by),
            lib-make-admin-item:havings(
                    $context-ids,
                    $country-identifiers,
                    $language-identifiers,
                    $names,
                    $definitions,
                    $preferred,
                    $sources),
                   if($uri > '')
                   then (
                   element openMDR:reference_uri {$uri})
                   else ()
                   )

   (: compose the document :)
   let $document :=
      element openMDR:Property {
            attribute item_registration_authority_identifier {$reg-auth},
            attribute data_identifier {$data-identifier},
            attribute version {$version},
            $content
           }

   let $collection := 'property'
   let $message := lib-forms:store-document($document)
   return
      if ($message='stored')
      then true()
      else response:redirect-to(xs:anyURI(concat("../web/login.xquery?calling_page=newProperty.xquery&",$message)))
};

declare function local:input-page(
   $message as xs:string?,
   $reg-auth as xs:string?,
   $administrative-note  as xs:string?,
   $administrative-status  as xs:string?,
   $administered-by  as xs:string?,
   $submitted-by  as xs:string?,
   $registered-by  as xs:string?,
   $context-ids  as xs:string*,
   $country-identifiers as xs:string*,
   $language-identifiers as xs:string*,
   $names as xs:string*,
   $definitions as xs:string*,
   $sources as xs:string*,
   $property_uri as xs:string?,
   $action as xs:string?,
   $preferred as xs:string?
   ) {

   let $skip-name := substring-after($action,'delete naming entry')
   let $skip-name-index := if ($skip-name>'') then xs:int($skip-name) else 0
   return

                This form will allow you to create a new property in the metadata repository

          <form name="new_property" action="newProperty.xquery" method="post" class="cagridForm" enctype="multipart/form-data">

           {lib-forms:edit-admin-item($reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $preferred,
                     $action)}

                       Property class specific properties

                               uri

                                  {
                                     lib-forms:find-concept-id('property_uri','get concept',$property_uri)
                                  }

	<input type="submit" name="update" value="Store"/>	<input type="submit" name="update" value="Clear"/>

          </form>

{$message}

   };

declare function local:success-page()
{
   let $calling-page := request:get-parameter("calling-page","")
   return

Property class created

Return to maintenance menu

Create another property class

};

declare option exist:serialize "media-type=text/html method=xhtml doctype-public=-//W3C//DTD XHTML 1.0 Transitional//EN doctype-system=http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd";

   session:create(),
   let $title as xs:string := "Creating a New Property"
   let $reg-auth := request:get-parameter('registration-authority','')
   let $administrative-note := request:get-parameter('administrative-note','')
   let $administrative-status := request:get-parameter('administrative-status','')
   let $administered-by := request:get-parameter('administered-by','')
   let $submitted-by := request:get-parameter('submitted-by','')
   let $registered-by := request:get-parameter('registered-by','')
   let $context-ids := request:get-parameter('context-ids',())
   let $country-identifiers := request:get-parameter('country-identifiers',())
   let $language-identifiers := request:get-parameter('language-identifiers',())
   let $names := request:get-parameter('names',())
   let $definitions := request:get-parameter('definitions',())
   let $sources := request:get-parameter('sources',())
   let $property_uri := request:get-parameter('property_uri','')
   let $preferred := request:get-parameter('preferred','')
   let $action := request:get-parameter('update','')

   return

      lib-rendering:txfrm-webpage(
      $title,
      if ($action='Store')
      then
         (
         if (
               local:property
                  (
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $property_uri,
                     $preferred
                  )
            )
         then local:success-page()
         else (local:input-page(
            'could not store document',
                     $reg-auth,
                     $administrative-note,
                     $administrative-status,
                     $administered-by,
                     $submitted-by,
                     $registered-by,
                     $context-ids,
                     $country-identifiers,
                     $language-identifiers,
                     $names,
                     $definitions,
                     $sources,
                     $property_uri,
                     $action,
                     $preferred
                  )
               )
         )
      else local:input-page
               (
               '',
               $reg-auth,
               $administrative-note,
               $administrative-status,
               $administered-by,
               $submitted-by,
               $registered-by,
               $context-ids,
               $country-identifiers,
               $language-identifiers,
               $names,
               $definitions,
               $sources,
               $property_uri,
               $action,
               $preferred
               )
         )


Removed file/folder

Removed file/folder

<results>
  {
    for $b in doc("http://bstore1.example.com/bib.xml")/bib/book,
        $t in $b/title,
        $a in $b/author
    return
        <result>
            { $t }
            { $a }
        </result>
  }
</results>