Added signatures for the XPath functions.

(:~
 : @author www.w3c.org
 :)
module namespace  fn = "http://www.w3.org/2005/xpath-functions";

(:~
 : @see for semantics please check fn:abs
 :)
declare function  fn:abs ($arg as numeric?) as numeric?  external;

(:~
 : @see for semantics please check fn:adjust-date-to-timezone
 :)
declare function  fn:adjust-date-to-timezone ( $arg as xs:date?) as xs:date?  external;

(:~
 : @see for semantics please check fn:adjust-date-to-timezone
 :)
declare function  fn:adjust-date-to-timezone ( $arg as xs:date?, $timezone as xs:dayTimeDuration?) as xs:date?  external;

(:~
 : @see for semantics please check fn:adjust-dateTime-to-timezone
 :)
declare function  fn:adjust-dateTime-to-timezone ( $arg as xs:dateTime?) as xs:dateTime?  external;

(:~
 : @see for semantics please check fn:adjust-dateTime-to-timezone
 :)
declare function  fn:adjust-dateTime-to-timezone ( $arg as xs:dateTime?, $timezone as xs:dayTimeDuration?) as xs:dateTime?  external;

(:~
 : @see for semantics please check fn:adjust-time-to-timezone
 :)
declare function  fn:adjust-time-to-timezone ( $arg as xs:time?) as xs:time?  external;

(:~
 : @see for semantics please check fn:adjust-time-to-timezone
 :)
declare function  fn:adjust-time-to-timezone ( $arg as xs:time?, $timezone as xs:dayTimeDuration?) as xs:time?  external;

(:~
 : @see for semantics please check fn:avg
 :)
declare function  fn:avg ($arg as xs:anyAtomicType*) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:base-uri
 :)
declare function  fn:base-uri () as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:base-uri
 :)
declare function  fn:base-uri ($arg as node()?) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:boolean
 :)
declare function  fn:boolean ($arg as item()*) as xs:boolean  external;

(:~
 : @see for semantics please check fn:ceiling
 :)
declare function  fn:ceiling ($arg as numeric?) as numeric?  external;

(:~
 : @see for semantics please check fn:codepoint-equal
 :)
declare function  fn:codepoint-equal ($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:boolean?  external;

(:~
 : @see for semantics please check fn:codepoints-to-string
 :)
declare function  fn:codepoints-to-string ( $arg as xs:integer*) as xs:string  external;

(:~
 : @see for semantics please check fn:collection
 :)
declare function  fn:collection () as node()*  external;

(:~
 : @see for semantics please check fn:collection
 :)
declare function  fn:collection ($arg as xs:string?) as node()*  external;

(:~
 : @see for semantics please check fn:compare
 :)
declare function  fn:compare ($comparand1 as xs:string?, $comparand2 as xs:string?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:compare
 :)
declare function  fn:compare ($comparand1 as xs:string?, $comparand2 as xs:string?, $collation as xs:string) as xs:integer?  external;

(:~
 : @see for semantics please check fn:concat
 :)
declare function  fn:concat ($arg1 as xs:anyAtomicType?, $arg2 as xs:anyAtomicType?) as xs:string  external;

(:~
 : @see for semantics please check fn:contains
 :)
declare function  fn:contains ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean  external;

(:~
 : @see for semantics please check fn:contains
 :)
declare function  fn:contains ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:count
 :)
declare function  fn:count ($arg as item()*) as xs:integer  external;

(:~
 : @see for semantics please check fn:current-date
 :)
declare function  fn:current-date () as xs:date  external;

(:~
 : @see for semantics please check fn:current-dateTime
 :)
declare function  fn:current-dateTime () as xs:dateTime  external;

(:~
 : @see for semantics please check fn:current-time
 :)
declare function  fn:current-time () as xs:time  external;

(:~
 : @see for semantics please check fn:data
 :)
declare function  fn:data ($arg as item()*) as xs:anyAtomicType*  external;

(:~
 : @see for semantics please check fn:dateTime
 :)
declare function  fn:dateTime ($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime?  external;

(:~
 : @see for semantics please check fn:day-from-date
 :)
declare function  fn:day-from-date ($arg as xs:date?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:day-from-dateTime
 :)
declare function  fn:day-from-dateTime ( $arg as xs:dateTime?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:days-from-duration
 :)
declare function  fn:days-from-duration ( $arg as xs:duration?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:deep-equal
 :)
declare function  fn:deep-equal ($parameter1 as item()*, $parameter2 as item()*) as xs:boolean  external;

(:~
 : @see for semantics please check fn:deep-equal
 :)
declare function  fn:deep-equal ($parameter1 as item()*, $parameter2 as item()*, $collation as string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:default-collation
 :)
declare function  fn:default-collation () as xs:string  external;

(:~
 : @see for semantics please check fn:distinct-values
 :)
declare function  fn:distinct-values ($arg as xs:anyAtomicType*) as xs:anyAtomicType*  external;

(:~
 : @see for semantics please check fn:distinct-values
 :)
declare function  fn:distinct-values ($arg as xs:anyAtomicType*, $collation as xs:string) as xs:anyAtomicType*  external;

(:~
 : @see for semantics please check fn:doc
 :)
declare function  fn:doc ($uri as xs:string?) as document-node()?  external;

(:~
 : @see for semantics please check fn:doc-available
 :)
declare function  fn:doc-available ($uri as xs:string?) as xs:boolean  external;

(:~
 : @see for semantics please check fn:document-uri
 :)
declare function  fn:document-uri ($arg as node()?) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:empty
 :)
declare function  fn:empty ($arg as item()*) as xs:boolean  external;

(:~
 : @see for semantics please check fn:encode-for-uri
 :)
declare function  fn:encode-for-uri ($uri-part as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:ends-with
 :)
declare function  fn:ends-with ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean  external;

(:~
 : @see for semantics please check fn:ends-with
 :)
declare function  fn:ends-with ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:error
 :)
declare function  fn:error () as none  external;

(:~
 : @see for semantics please check fn:error
 :)
declare function  fn:error ($error as xs:QName) as none  external;

(:~
 : @see for semantics please check fn:error
 :)
declare function  fn:error ($error as xs:QName?, $description as xs:string) as none  external;

(:~
 : @see for semantics please check fn:error
 :)
declare function  fn:error ($error as xs:QName?, $description as xs:string, $error-object as item()*) as none  external;

(:~
 : @see for semantics please check fn:escape-html-uri
 :)
declare function  fn:escape-html-uri ($uri as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:exactly-one
 :)
declare function  fn:exactly-one ($arg as item()*) as item()  external;

(:~
 : @see for semantics please check fn:exists
 :)
declare function  fn:exists ($arg as item()*) as xs:boolean  external;

(:~
 : @see for semantics please check fn:false
 :)
declare function  fn:false () as xs:boolean  external;

(:~
 : @see for semantics please check fn:floor
 :)
declare function  fn:floor ($arg as numeric?) as numeric?  external;

(:~
 : @see for semantics please check fn:hours-from-dateTime
 :)
declare function  fn:hours-from-dateTime ( $arg as xs:dateTime?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:hours-from-duration
 :)
declare function  fn:hours-from-duration ( $arg as xs:duration?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:hours-from-time
 :)
declare function  fn:hours-from-time ($arg as xs:time?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:id
 :)
declare function  fn:id ($arg as xs:string*) as element()*  external;

(:~
 : @see for semantics please check fn:id
 :)
declare function  fn:id ($arg as xs:string*, $node as node()) as element()*  external;

(:~
 : @see for semantics please check fn:idref
 :)
declare function  fn:idref ($arg as xs:string*) as node()*  external;

(:~
 : @see for semantics please check fn:idref
 :)
declare function  fn:idref ($arg as xs:string*, $node as node()) as node()*  external;

(:~
 : @see for semantics please check fn:implicit-timezone
 :)
declare function  fn:implicit-timezone () as xs:dayTimeDuration  external;

(:~
 : @see for semantics please check fn:in-scope-prefixes
 :)
declare function  fn:in-scope-prefixes ( $element as element()) as xs:string*  external;

(:~
 : @see for semantics please check fn:index-of
 :)
declare function  fn:index-of ($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType) as xs:integer*  external;

(:~
 : @see for semantics please check fn:index-of
 :)
declare function  fn:index-of ($seqParam as xs:anyAtomicType*, $srchParam as xs:anyAtomicType, $collation as xs:string) as xs:integer*  external;

(:~
 : @see for semantics please check fn:insert-before
 :)
declare function  fn:insert-before ($target as item()*, $position as xs:integer, $inserts as item()*) as item()*  external;

(:~
 : @see for semantics please check fn:iri-to-uri
 :)
declare function  fn:iri-to-uri ($iri as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:lang
 :)
declare function  fn:lang ($testlang as xs:string?) as xs:boolean  external;

(:~
 : @see for semantics please check fn:lang
 :)
declare function  fn:lang ($testlang as xs:string?, $node as node()) as xs:boolean  external;

(:~
 : @see for semantics please check fn:last
 :)
declare function  fn:last () as xs:integer  external;

(:~
 : @see for semantics please check fn:local-name
 :)
declare function  fn:local-name () as xs:string  external;

(:~
 : @see for semantics please check fn:local-name
 :)
declare function  fn:local-name ($arg as node()?) as xs:string  external;

(:~
 : @see for semantics please check fn:local-name-from-QName
 :)
declare function  fn:local-name-from-QName ( $arg as xs:QName?) as xs:NCName?  external;

(:~
 : @see for semantics please check fn:lower-case
 :)
declare function  fn:lower-case ($arg as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:matches
 :)
declare function  fn:matches ($input as xs:string?, $pattern as xs:string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:matches
 :)
declare function  fn:matches ($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:max
 :)
declare function  fn:max ($arg as xs:anyAtomicType*) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:max
 :)
declare function  fn:max ($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:min
 :)
declare function  fn:min ($arg as xs:anyAtomicType*) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:min
 :)
declare function  fn:min ($arg as xs:anyAtomicType*, $collation as string) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:minutes-from-dateTime
 :)
declare function  fn:minutes-from-dateTime ( $arg as xs:dateTime?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:minutes-from-duration
 :)
declare function  fn:minutes-from-duration ( $arg as xs:duration?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:minutes-from-time
 :)
declare function  fn:minutes-from-time ( $arg as xs:time?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:month-from-date
 :)
declare function  fn:month-from-date ($arg as xs:date?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:month-from-dateTime
 :)
declare function  fn:month-from-dateTime ( $arg as xs:dateTime?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:months-from-duration
 :)
declare function  fn:months-from-duration ( $arg as xs:duration?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:name
 :)
declare function  fn:name () as xs:string  external;

(:~
 : @see for semantics please check fn:name
 :)
declare function  fn:name ($arg as node()?) as xs:string  external;

(:~
 : @see for semantics please check fn:namespace-uri
 :)
declare function  fn:namespace-uri () as xs:anyURI  external;

(:~
 : @see for semantics please check fn:namespace-uri
 :)
declare function  fn:namespace-uri ($arg as node()?) as xs:anyURI  external;

(:~
 : @see for semantics please check fn:namespace-uri-for-prefix
 :)
declare function  fn:namespace-uri-for-prefix ( $prefix as xs:string?, $element as element()) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:namespace-uri-from-QName
 :)
declare function  fn:namespace-uri-from-QName ( $arg as xs:QName?) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:nilled
 :)
declare function  fn:nilled ($arg as node()?) as xs:boolean?  external;

(:~
 : @see for semantics please check fn:node-name
 :)
declare function  fn:node-name ($arg as node()?) as xs:QName?  external;

(:~
 : @see for semantics please check fn:normalize-space
 :)
declare function  fn:normalize-space () as xs:string  external;

(:~
 : @see for semantics please check fn:normalize-space
 :)
declare function  fn:normalize-space ($arg as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:normalize-unicode
 :)
declare function  fn:normalize-unicode ( $arg as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:normalize-unicode
 :)
declare function  fn:normalize-unicode ( $arg as xs:string?, $normalizationForm as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:not
 :)
declare function  fn:not ($arg as item()*) as xs:boolean  external;

(:~
 : @see for semantics please check fn:number
 :)
declare function  fn:number () as xs:double  external;

(:~
 : @see for semantics please check fn:number
 :)
declare function  fn:number ($arg as xs:anyAtomicType?) as xs:double  external;

(:~
 : @see for semantics please check fn:one-or-more
 :)
declare function  fn:one-or-more ($arg as item()*) as item()+  external;

(:~
 : @see for semantics please check fn:position
 :)
declare function  fn:position () as xs:integer  external;

(:~
 : @see for semantics please check fn:prefix-from-QName
 :)
declare function  fn:prefix-from-QName ( $arg as xs:QName?) as xs:NCName?  external;

(:~
 : @see for semantics please check fn:QName
 :)
declare function  fn:QName ($paramURI as xs:string?, $paramQName as xs:string) as xs:QName  external;

(:~
 : @see for semantics please check fn:remove
 :)
declare function  fn:remove ($target as item()*, $position as xs:integer) as item()*  external;

(:~
 : @see for semantics please check fn:replace
 :)
declare function  fn:replace ($input as xs:string?, $pattern as xs:string, $replacement as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:replace
 :)
declare function  fn:replace ($input as xs:string?, $pattern as xs:string, $replacement as xs:string, $flags as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:resolve-QName
 :)
declare function  fn:resolve-QName ($qname as xs:string?, $element as element()) as xs:QName?  external;

(:~
 : @see for semantics please check fn:resolve-uri
 :)
declare function  fn:resolve-uri ($relative as xs:string?) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:resolve-uri
 :)
declare function  fn:resolve-uri ($relative as xs:string?, $base as xs:string) as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:reverse
 :)
declare function  fn:reverse ($arg as item()*) as item()*  external;

(:~
 : @see for semantics please check fn:root
 :)
declare function  fn:root () as node()  external;

(:~
 : @see for semantics please check fn:root
 :)
declare function  fn:root ($arg as node()?) as node()?  external;

(:~
 : @see for semantics please check fn:round
 :)
declare function  fn:round ($arg as numeric?) as numeric?  external;

(:~
 : @see for semantics please check fn:round-half-to-even
 :)
declare function  fn:round-half-to-even ( $arg as numeric?) as numeric?  external;

(:~
 : @see for semantics please check fn:round-half-to-even
 :)
declare function  fn:round-half-to-even ( $arg as numeric?, $precision as xs:integer) as numeric?  external;

(:~
 : @see for semantics please check fn:seconds-from-dateTime
 :)
declare function  fn:seconds-from-dateTime ( $arg as xs:dateTime?) as xs:decimal?  external;

(:~
 : @see for semantics please check fn:seconds-from-duration
 :)
declare function  fn:seconds-from-duration ( $arg as xs:duration?) as xs:decimal?  external;

(:~
 : @see for semantics please check fn:seconds-from-time
 :)
declare function  fn:seconds-from-time ( $arg as xs:time?) as xs:decimal?  external;

(:~
 : @see for semantics please check fn:starts-with
 :)
declare function  fn:starts-with ($arg1 as xs:string?, $arg2 as xs:string?) as xs:boolean  external;

(:~
 : @see for semantics please check fn:starts-with
 :)
declare function  fn:starts-with ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:boolean  external;

(:~
 : @see for semantics please check fn:static-base-uri
 :)
declare function  fn:static-base-uri () as xs:anyURI?  external;

(:~
 : @see for semantics please check fn:string
 :)
declare function  fn:string () as xs:string  external;

(:~
 : @see for semantics please check fn:string
 :)
declare function  fn:string ($arg as item()?) as xs:string  external;

(:~
 : @see for semantics please check fn:string-join
 :)
declare function  fn:string-join ($arg1 as xs:string*, $arg2 as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:string-length
 :)
declare function  fn:string-length () as xs:integer  external;

(:~
 : @see for semantics please check fn:string-length
 :)
declare function  fn:string-length ($arg as xs:string?) as xs:integer  external;

(:~
 : @see for semantics please check fn:string-to-codepoints
 :)
declare function  fn:string-to-codepoints ( $arg as xs:string?) as xs:integer*  external;

(:~
 : @see for semantics please check fn:subsequence
 :)
declare function  fn:subsequence ($sourceSeq as item()*, $startingLoc as xs:double) as item()*  external;

(:~
 : @see for semantics please check fn:subsequence
 :)
declare function  fn:subsequence ($sourceSeq as item()*, $startingLoc as xs:double, $length as xs:double) as item()*  external;

(:~
 : @see for semantics please check fn:substring
 :)
declare function  fn:substring ($sourceString as xs:string?, $startingLoc as xs:double) as xs:string  external;

(:~
 : @see for semantics please check fn:substring
 :)
declare function  fn:substring ($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) as xs:string  external;

(:~
 : @see for semantics please check fn:substring-after
 :)
declare function  fn:substring-after ($arg1 as xs:string?, $arg2 as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:substring-after
 :)
declare function  fn:substring-after ($arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:substring-before
 :)
declare function  fn:substring-before ( $arg1 as xs:string?, $arg2 as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:substring-before
 :)
declare function  fn:substring-before ( $arg1 as xs:string?, $arg2 as xs:string?, $collation as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:sum
 :)
declare function  fn:sum ($arg as xs:anyAtomicType*) as xs:anyAtomicType  external;

(:~
 : @see for semantics please check fn:sum
 :)
declare function  fn:sum ($arg as xs:anyAtomicType*, $zero as xs:anyAtomicType?) as xs:anyAtomicType?  external;

(:~
 : @see for semantics please check fn:timezone-from-date
 :)
declare function  fn:timezone-from-date ( $arg as xs:date?) as xs:dayTimeDuration?  external;

(:~
 : @see for semantics please check fn:timezone-from-dateTime
 :)
declare function  fn:timezone-from-dateTime ( $arg as xs:dateTime?) as xs:dayTimeDuration?  external;

(:~
 : @see for semantics please check fn:timezone-from-time
 :)
declare function  fn:timezone-from-time ( $arg as xs:time?) as xs:dayTimeDuration?  external;

(:~
 : @see for semantics please check fn:tokenize
 :)
declare function  fn:tokenize ($input as xs:string?, $pattern as xs:string) as xs:string*  external;

(:~
 : @see for semantics please check fn:tokenize
 :)
declare function  fn:tokenize ($input as xs:string?, $pattern as xs:string, $flags as xs:string) as xs:string*  external;

(:~
 : @see for semantics please check fn:trace
 :)
declare function  fn:trace ($value as item()*, $label as xs:string) as item()*  external;

(:~
 : @see for semantics please check fn:translate
 :)
declare function  fn:translate ($arg as xs:string?, $mapString as xs:string, $transString as xs:string) as xs:string  external;

(:~
 : @see for semantics please check fn:true
 :)
declare function  fn:true () as xs:boolean  external;

(:~
 : @see for semantics please check fn:unordered
 :)
declare function  fn:unordered ($sourceSeq as item()*) as item()*  external;

(:~
 : @see for semantics please check fn:upper-case
 :)
declare function  fn:upper-case ($arg as xs:string?) as xs:string  external;

(:~
 : @see for semantics please check fn:year-from-date
 :)
declare function  fn:year-from-date ($arg as xs:date?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:year-from-dateTime
 :)
declare function  fn:year-from-dateTime ( $arg as xs:dateTime?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:years-from-duration
 :)
declare function  fn:years-from-duration ( $arg as xs:duration?) as xs:integer?  external;

(:~
 : @see for semantics please check fn:zero-or-one
 :)
declare function  fn:zero-or-one ($arg as item()*) as item()?  external;

(:~
 : @author www.w3c.org
 :)
module namespace  fn = "http://www.w3.org/2005/xpath-functions";

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-abs
 :)
declare function fn:abs() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-adjust-date-to-timezone
 :)
declare function fn:adjust-date-to-timezone() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone
 :)
declare function fn:adjust-dateTime-to-timezone() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-adjust-time-to-timezone
 :)
declare function fn:adjust-time-to-timezone() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-avg
 :)
declare function fn:avg() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-base-uri
 :)
declare function fn:base-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-boolean
 :)
declare function fn:boolean() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-ceiling
 :)
declare function fn:ceiling() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-codepoint-equal
 :)
declare function fn:codepoint-equal() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-codepoints-to-string
 :)
declare function fn:codepoints-to-string() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-collection
 :)
declare function fn:collection() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-compare
 :)
declare function fn:compare() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-concat
 :)
declare function fn:concat() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-contains
 :)
declare function fn:contains() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-count
 :)
declare function fn:count() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-current-date
 :)
declare function fn:current-date() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-current-dateTime
 :)
declare function fn:current-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-current-time
 :)
declare function fn:current-time() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-data
 :)
declare function fn:data() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-day-from-date
 :)
declare function fn:day-from-date() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-day-from-dateTime
 :)
declare function fn:day-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-days-from-duration
 :)
declare function fn:days-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-deep-equal
 :)
declare function fn:deep-equal() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-default-collation
 :)
declare function fn:default-collation() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-distinct-values
 :)
declare function fn:distinct-values() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-doc
 :)
declare function fn:doc() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-doc-available
 :)
declare function fn:doc-available() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-document-uri
 :)
declare function fn:document-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-empty
 :)
declare function fn:empty() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-encode-for-uri
 :)
declare function fn:encode-for-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-ends-with
 :)
declare function fn:ends-with() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-escape-html-uri
 :)
declare function fn:escape-html-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-exactly-one
 :)
declare function fn:exactly-one() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-exists
 :)
declare function fn:exists() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-false
 :)
declare function fn:false() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-floor
 :)
declare function fn:floor() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-hours-from-dateTime
 :)
declare function fn:hours-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-hours-from-duration
 :)
declare function fn:hours-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-hours-from-time
 :)
declare function fn:hours-from-time() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-id
 :)
declare function fn:id() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-idref
 :)
declare function fn:idref() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-implicit-timezone
 :)
declare function fn:implicit-timezone() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-in-scope-prefixes
 :)
declare function fn:in-scope-prefixes() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-index-of
 :)
declare function fn:index-of() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-insert-before
 :)
declare function fn:insert-before() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-iri-to-uri
 :)
declare function fn:iri-to-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-lang
 :)
declare function fn:lang() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-last
 :)
declare function fn:last() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-local-name
 :)
declare function fn:local-name() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-local-name-from-QName
 :)
declare function fn:local-name-from-QName() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-lower-case
 :)
declare function fn:lower-case() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-matches
 :)
declare function fn:matches() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-max
 :)
declare function fn:max() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-min
 :)
declare function fn:min() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-minutes-from-dateTime
 :)
declare function fn:minutes-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-minutes-from-duration
 :)
declare function fn:minutes-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-minutes-from-time
 :)
declare function fn:minutes-from-time() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-month-from-date
 :)
declare function fn:month-from-date() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-month-from-dateTime
 :)
declare function fn:month-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-months-from-duration
 :)
declare function fn:months-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-name
 :)
declare function fn:name() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-namespace-uri
 :)
declare function fn:namespace-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-namespace-uri-for-prefix
 :)
declare function fn:namespace-uri-for-prefix() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-namespace-uri-from-QName
 :)
declare function fn:namespace-uri-from-QName() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-nilled
 :)
declare function fn:nilled() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-node-name
 :)
declare function fn:node-name() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-normalize-space
 :)
declare function fn:normalize-space() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-normalize-unicode
 :)
declare function fn:normalize-unicode() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-not
 :)
declare function fn:not() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-number
 :)
declare function fn:number() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-one-or-more
 :)
declare function fn:one-or-more() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-position
 :)
declare function fn:position() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-prefix-from-QName
 :)
declare function fn:prefix-from-QName() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-QName
 :)
declare function fn:QName() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-remove
 :)
declare function fn:remove() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-replace
 :)
declare function fn:replace() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-resolve-QName
 :)
declare function fn:resolve-QName() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-resolve-uri
 :)
declare function fn:resolve-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-reverse
 :)
declare function fn:reverse() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-root
 :)
declare function fn:root() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-round
 :)
declare function fn:round() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-round-half-to-even
 :)
declare function fn:round-half-to-even() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-seconds-from-dateTime
 :)
declare function fn:seconds-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-seconds-from-duration
 :)
declare function fn:seconds-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-seconds-from-time
 :)
declare function fn:seconds-from-time() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-starts-with
 :)
declare function fn:starts-with() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-static-base-uri
 :)
declare function fn:static-base-uri() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-string
 :)
declare function fn:string() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-string-join
 :)
declare function fn:string-join() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-string-length
 :)
declare function fn:string-length() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-string-to-codepoints
 :)
declare function fn:string-to-codepoints() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-subsequence
 :)
declare function fn:subsequence() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-substring
 :)
declare function fn:substring() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-substring-after
 :)
declare function fn:substring-after() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-substring-before
 :)
declare function fn:substring-before() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-sum
 :)
declare function fn:sum() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-timezone-from-date
 :)
declare function fn:timezone-from-date() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-timezone-from-dateTime
 :)
declare function fn:timezone-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-timezone-from-time
 :)
declare function fn:timezone-from-time() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-tokenize
 :)
declare function fn:tokenize() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-translate
 :)
declare function fn:translate() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-true
 :)
declare function fn:true() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-unordered
 :)
declare function fn:unordered() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-upper-case
 :)
declare function fn:upper-case() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-year-from-date
 :)
declare function fn:year-from-date() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-year-from-dateTime
 :)
declare function fn:year-from-dateTime() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-years-from-duration
 :)
declare function fn:years-from-duration() external;

(:~
 : @see for semantics please check http://www.w3.org/TR/xpath-functions/#func-zero-or-one
 :)
declare function fn:zero-or-one() external;


Improvements in code elegance :-)

Improvements in code elegance :-)

svn path=/trunk/eXist/; revision=4779

declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace empty="";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $revision := system:get-revision()
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename="results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml"" ) )

let $cases := fn:collection(  '/db/XQTS' )//test-case
return
<test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult">
    <implementation name="eXist-db" version="{$product-version} (revision {$revision} {$product-build})" anonymous-result-column="false">

        <organization name="eXist Open Source Native XML database"  website="http://www.exist-db.org" anonymous="false"/>

        <submittor name="eXist XQTS testsuite runner" email="eXistAdmin@gmail.com"/>

        <description>

eXist is an Open Source native XML database featuring efficient,
                index-based XQuery processing, automatic indexing, extensions for full-text
                search,  XUpdate  support and tight integration with existing XML development tools.

        </description>

        <implementation-defined-items>

        </implementation-defined-items>

        <features>

        <feature name="Minimal Conformance" supported="true"/>
        <feature name="Schema Import" supported="false"/>
        <feature name="Schema Validation" supported="false"/>
        <feature name="Static Typing" supported="false"/>
        <feature name="Static Typing Extensions" supported="false"/>
        <feature name="Full Axis" supported="true"/>
        <feature name="Module" supported="true"/>
        <feature name="Serialization" supported="true"/>
        <feature name="Trivial XML Embedding" supported="false"/>
				  </features>

        <context-properties>

        </context-properties>

    </implementation>

    <syntax>XQuery</syntax>

    <test-run dateRun="{fn:current-dateTime()}">
        <test-suite version="{$test-suite}"/>
        <transformation>

No unusual transformations.

        </transformation>
        <comparison>

No unusual comparisons

        </comparison>
        <otherComments>

The test run took {let $b := for $a in $cases//@dateRun return xs:time($a)
return (max($b) - min($b)) div xs:dayTimeDuration('PT1S')} seconds.

        </otherComments>
    </test-run>

{
    for $case in $cases
    order by $case/@name
    return <test-case name="{$case/@name}" result="{$case/@result}" />
}
</test-suite-result>

declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace empty="";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $revision := system:get-revision()
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename="results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml"" ) )

let $cases := fn:collection(  '/db/XQTS' )//test-case
return
<test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult">
    <implementation name="eXist-db" version="{$product-version} (revision {$revision} {$product-build})" anonymous-result-column="false">

        <organization name="eXist Open Source Native XML database"  website="http://www.exist-db.org" anonymous="false"/>

        <submittor name="eXist XQTS testsuite runner" email="eXistAdmin@gmail.com"/>

        <description>

eXist is an Open Source native XML database featuring efficient,
                index-based XQuery processing, automatic indexing, extensions for full-text
                search,  XUpdate  support and tight integration with existing XML development tools.

        </description>

        <implementation-defined-items>

        </implementation-defined-items>

        <features>

        <feature name="Minimal Conformance" supported="true"/>
        <feature name="Schema Import" supported="false"/>
        <feature name="Schema Validation" supported="false"/>
        <feature name="Static Typing" supported="false"/>
        <feature name="Static Typing Extensions" supported="false"/>
        <feature name="Full Axis" supported="true"/>
        <feature name="Module" supported="true"/>
        <feature name="Serialization" supported="true"/>
        <feature name="Trivial XML Embedding" supported="false"/>
				  </features>

        <context-properties>

        </context-properties>

    </implementation>

    <syntax>XQuery</syntax>

    <test-run dateRun="{fn:current-dateTime()}">
        <test-suite version="{$test-suite}"/>
        <transformation>

No unusual transformations.

        </transformation>
        <comparison>

No unusual comparisons

        </comparison>
        <otherComments>

The test run took {let $b := for $a in $cases//@dateRun order by xs:time($a) return xs:time($a)
return ($b[last()] - $b[1]) div xs:dayTimeDuration('PT1S')} seconds.

        </otherComments>
    </test-run>

{
    for $case in $cases
    order by $case/@name
    return <test-case name="{$case/@name}" result="{$case/@result}" />
}
</test-suite-result>


*** empty log message ***

*** empty log message ***

svn path=/trunk/eXist-1.0/; revision=1043

(:  This XQuery is used to generate a collection listing
    in response to a GET request on a collection
:)
xquery version "1.0";

(::pragma exist:output-size-limit -1 ::)

import module namespace xdb="http://exist-db.org/xquery/xmldb";

declare namespace f="urn:my-functions";

declare variable $f:months {
	("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
	"Nov", "Dec")
};

declare function f:format-date($date as xs:dateTime) as xs:string {
	string-join((
		item-at($f:months, month-from-date($date)),
		day-from-date($date),
		year-from-date($date)), " ")
};

declare function f:format-int($component as xs:integer) as xs:string {
	if($component lt 10) then
		concat("0", $component)
	else
		xs:string($component)
};

declare function f:format-time($time as xs:dateTime) as xs:string {
	concat(
		f:format-int(hours-from-dateTime($time)), ":",
		f:format-int(minutes-from-dateTime($time)), ":",
		f:format-int(xs:integer(seconds-from-dateTime($time)))
	)
};

declare function f:format-dateTime($dt as xs:dateTime) as xs:string {
    concat(f:format-date($dt), " ", f:format-time($dt))
};

declare function f:display-child-resources($collection as xs:string)
as element()* {
    for $child in xdb:get-child-resources($collection)
    order by $child
    return

            {$child}
            {xdb:permissions-to-string(xdb:get-permissions($collection, $child))}
            {xdb:get-owner($collection, $child)}
            {xdb:get-group($collection, $child)}
            {f:format-dateTime(xdb:created($collection, $child))}
            {f:format-dateTime(xdb:last-modified($collection, $child))}
            {xdb:size($collection, $child) div 1024}

};

declare function f:display-child-collections($collection as xs:string)
as element()* {
    for $child in xdb:get-child-collections($collection)
    let $path := concat($collection, '/', $child),
        $created := xdb:created($path)
    order by $child
    return

            {$child}
            {xdb:permissions-to-string(xdb:get-permissions($path))}
            {xdb:get-owner($path)}
            {xdb:get-group($path)}
            {f:format-dateTime($created)}

};

        <title>{$collection}</title>

Contents of {$collection}

                Name
                Permissions
                Owner
                Group
                Created
                Last Modified

            {f:display-child-collections($collection)}
            {f:display-child-resources($collection)}

(:  This XQuery is used to generate a collection listing
    in response to a GET request on a collection
:)
xquery version "1.0";

import module namespace xdb="http://exist-db.org/xquery/xmldb";

declare namespace f="urn:my-functions";

declare variable $f:months {
	("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
	"Nov", "Dec")
};

declare function f:format-date($date as xs:dateTime) as xs:string {
	string-join((
		item-at($f:months, month-from-date($date)),
		day-from-date($date),
		year-from-date($date)), " ")
};

declare function f:format-int($component as xs:integer) as xs:string {
	if($component lt 10) then
		concat("0", $component)
	else
		xs:string($component)
};

declare function f:format-time($time as xs:dateTime) as xs:string {
	concat(
		f:format-int(hours-from-dateTime($time)), ":",
		f:format-int(minutes-from-dateTime($time)), ":",
		f:format-int(xs:integer(seconds-from-dateTime($time)))
	)
};

declare function f:format-dateTime($dt as xs:dateTime) as xs:string {
    concat(f:format-date($dt), " ", f:format-time($dt))
};

declare function f:display-child-resources($collection as xs:string)
as element()* {
    for $child in xdb:get-child-resources($collection)
    order by $child
    return

            {$child}
            {xdb:permissions-to-string(xdb:get-permissions($collection, $child))}
            {xdb:get-owner($collection, $child)}
            {xdb:get-group($collection, $child)}
            {f:format-dateTime(xdb:created($collection, $child))}
            {f:format-dateTime(xdb:last-modified($collection, $child))}
            {xdb:size($collection, $child) div 1024}

};

declare function f:display-child-collections($collection as xs:string)
as element()* {
    for $child in xdb:get-child-collections($collection)
    let $path := concat($collection, '/', $child),
        $created := xdb:created($path)
    order by $child
    return

            {$child}
            {xdb:permissions-to-string(xdb:get-permissions($path))}
            {xdb:get-owner($path)}
            {xdb:get-group($path)}
            {f:format-dateTime($created)}

};

        <title>{$collection}</title>

Contents of {$collection}

                Name
                Permissions
                Owner
                Group
                Created
                Last Modified

            {f:display-child-collections($collection)}
            {f:display-child-resources($collection)}


Added CSS class matching (needs refactoring)

xquery version "3.0";

(:~
 : Origami transformers.
 :
 : @version 0.3
 : @author Marc van Grootel
 : @see https://github.com/xokomola/origami
 :)

module namespace xf = 'http://xokomola.com/xquery/origami/xform';

(:~
 : Transforms input, using the specified templates.
 :)
declare function xf:transform($templates as map(*)*, $input as node()) as node() {
    xf:transform($templates)($input)
};

(:~
 : Returns a node transformation function.
 :)
declare function xf:transform($templates as map(*)*) as function(*) {
    function ($nodes as item()*) as item()* {
        xf:apply($nodes, $templates)
    }
};

(:~
 : Identity transformer.
 :)
declare function xf:transform() { xf:transform(()) };

(:~
 : Extracts nodes from input, using the specified selectors.
 :)
declare function xf:extract($selectors as map(*)*, $input as node()) as node() {
    xf:extract($selectors)($input)
};

(:~
 : Returns an extractor function that only returns selected nodes.
 :)
declare function xf:extract($selectors as map(*)*) as function(*) {
    function ($nodes as item()*) as item()* {
        xf:select($nodes, $selectors)
    }
};

(:~
 : Defines a template.
 :
 : A template takes a selector string or function and
 : a node transformation function or the items to return as
 : the template body.
 : Providing invalid matcher returns empty sequence.
 :)
declare function xf:template($match, $body) as map(*)? {
    let $match :=
        typeswitch ($match)
        case xs:string return xf:css-matches(?, xf:css-matcher($match))
        case function(item()) as xs:boolean return $match
        default return ()
    let $body :=
        typeswitch ($body)
        case empty-sequence() return function($node) { () }
        case function(item()) as item()* return $body
        case function(*)* return ()
        default return function($node) { $body }
    where $match instance of function(*) and $body instance of function(*)
    return
        map {
            'match': $match,
            'fn': $body
        }
};

declare function xf:select($match) as map(*)? {
    let $match :=
        typeswitch ($match)
        case xs:string return xf:css-matches(?, $match)
        case function(item()) as xs:boolean return $match
        default return ()
    where $match instance of function(*)
    return
        map {
            'match': $match,
            'fn': function($node) { $node }
        }
};

(:~
 : Copies nodes to output, and calls apply for
 : nodes that are wrapped inside <xf:apply>.
 :)
declare %private function xf:copy($nodes as item()*, $xform as map(*)*)
    as item()* {
    for $node in $nodes
    return
        if ($node/self::xf:apply) then
            xf:apply(($node/@*,$node/node()), $xform)
        else if ($node instance of element()) then
            element { node-name($node) } {
                $node/@*,
                xf:copy($node/node(), $xform)
            }
        else if ($node instance of document-node()) then
            document {
                xf:copy($node/node(), $xform)
            }
        else
            $node
};

(:~
 : Applies node transformations to nodes.
 :)
declare %private function xf:apply($nodes as item()*, $xform as map(*)*)
    as item()* {
    for $node in $nodes
    let $fn := xf:match($node, $xform)
    return
        if ($fn instance of function(*)) then
            xf:copy($fn($node), $xform)
        else if ($node instance of element()) then
            element { node-name($node) } {
                xf:apply($node/@*, $xform),
                xf:apply($node/node(), $xform)
            }
        else if ($node instance of document-node()) then
            document {
                xf:apply($node/node(), $xform)
            }
        else
            $node
};

(:~
 : Apply to be used from within templates.
 :)
declare function xf:apply($nodes as item()*)
    as element(xf:apply) {
    <xf:apply>{ $nodes }</xf:apply>
};

(:~
 : Look for nodes that match
 :)
declare %private function xf:select($nodes as item()*, $selectors as map(*)*)
    as item()* {
    for $node in $nodes
    let $fn := xf:match($node, $selectors)
    return
        if ($fn instance of function(*)) then
            xf:copy($fn($node), $selectors)
        else if ($node instance of element()) then
            xf:select($node/node(), $selectors)
        else if ($node instance of document-node()) then
            document {
                xf:select($node/node(), $selectors)
            }
        else
            ()
};

(:~
 : Find the first matching template for a node and return
 : it's node transformation function.
 :)
declare %private function xf:match($node as item(), $xform as map(*)*)
    as function(*)? {
    hof:until(
        function($templates as map(*)*) {
            let $is-match := head($templates)
            return
                empty($is-match) or
                not($is-match instance of map(*))
        },
        function($templates as map(*)*) {
            let $template := head($templates)
            return
                (
                    if ($template('match')($node)) then
                        $template('fn')
                    else
                        ()
                    ,
                    tail($templates)
                )
        },
        $xform
    )[1]
};

(:~
 : Returns true if the string expression matches the $node.
 :)
declare function xf:matches($node as item(), $expr as xs:string) as xs:boolean {
    typeswitch ($node)
    case element() return not($node/self::xf:*) and $expr = (name($node),'*')
    case attribute() return substring-after($expr, '@') = (name($node), '*')
    default return false()
};

(:~
 : Returns true if the css matcher matches the $node.
 : TODO: add class matching
 :)
declare function xf:css-matches($node as item(), $css-matcher as map(*)) as xs:boolean {
    typeswitch ($node)
    case element()
    return
        not($node/self::xf:*) and
        $css-matcher('el') = (local-name($node),'*') and
        ( not($css-matcher('id')) or $css-matcher('id') = trace($node/@id,'ID: ') ) and
        ( not($css-matcher('att')) or $css-matcher('att') = $node/@*/local-name() ) and
        ( not($css-matcher('class') or $node/@class) or
            ( every $cls in trace($css-matcher('class'),'CLS: ')
            satisfies contains(concat(' ',$node/@class,' '), concat(' ',$cls,' ')) ))
    case attribute()
    return
        not($css-matcher('att')) or $css-matcher('att') = local-name($node)
    default return false()
};

(:~
 : Build a CSS style matcher map.
 : TODO: fine-tune regexp
 : TODO: make it work for multiple expressions
 :)
declare function xf:css-matcher($expr) as map(*)* {
    for $expr in tokenize($expr,'\s+')[1]
    let $parsed :=
        for $token in analyze-string($expr, '[@#.]?[^@#.]+')/fn:match
        return
            string($token)
    return
         map {
            'att': for $att in $parsed[starts-with(.,'@')][1] return substring-after($att,'@'),
            'el': $parsed[not(starts-with(.,'.') or starts-with(.,'#') or starts-with(.,'@'))],
            'class': for $cls in $parsed[starts-with(.,'.')] return substring-after($cls,'.'),
            'id': for $id in $parsed[starts-with(.,'#')][1] return substring-after($id,'#')
        }
};

xquery version "3.0";

(:~
 : Origami transformers.
 :
 : @version 0.3
 : @author Marc van Grootel
 : @see https://github.com/xokomola/origami
 :)

module namespace xf = 'http://xokomola.com/xquery/origami/xform';

(:~
 : Transforms input, using the specified templates.
 :)
declare function xf:transform($templates as map(*)*, $input as node()) as node() {
    xf:transform($templates)($input)
};

(:~
 : Returns a node transformation function.
 :)
declare function xf:transform($templates as map(*)*) as function(*) {
    function ($nodes as item()*) as item()* {
        xf:apply($nodes, $templates)
    }
};

(:~
 : Identity transformer.
 :)
declare function xf:transform() { xf:transform(()) };

(:~
 : Extracts nodes from input, using the specified selectors.
 :)
declare function xf:extract($selectors as map(*)*, $input as node()) as node() {
    xf:extract($selectors)($input)
};

(:~
 : Returns an extractor function that only returns selected nodes.
 :)
declare function xf:extract($selectors as map(*)*) as function(*) {
    function ($nodes as item()*) as item()* {
        xf:select($nodes, $selectors)
    }
};

(:~
 : Defines a template.
 :
 : A template takes a selector string or function and
 : a node transformation function or the items to return as
 : the template body.
 : Providing invalid matcher returns empty sequence.
 :)
declare function xf:template($match, $body) as map(*)? {
    let $match :=
        typeswitch ($match)
        case xs:string return xf:css-matches(?, xf:css-matcher($match))
        case function(item()) as xs:boolean return $match
        default return ()
    let $body :=
        typeswitch ($body)
        case empty-sequence() return function($node) { () }
        case function(item()) as item()* return $body
        case function(*)* return ()
        default return function($node) { $body }
    where $match instance of function(*) and $body instance of function(*)
    return
        map {
            'match': $match,
            'fn': $body
        }
};

declare function xf:select($match) as map(*)? {
    let $match :=
        typeswitch ($match)
        case xs:string return xf:css-matches(?, $match)
        case function(item()) as xs:boolean return $match
        default return ()
    where $match instance of function(*)
    return
        map {
            'match': $match,
            'fn': function($node) { $node }
        }
};

(:~
 : Copies nodes to output, and calls apply for
 : nodes that are wrapped inside <xf:apply>.
 :)
declare %private function xf:copy($nodes as item()*, $xform as map(*)*)
    as item()* {
    for $node in $nodes
    return
        if ($node/self::xf:apply) then
            xf:apply(($node/@*,$node/node()), $xform)
        else if ($node instance of element()) then
            element { node-name($node) } {
                $node/@*,
                xf:copy($node/node(), $xform)
            }
        else if ($node instance of document-node()) then
            document {
                xf:copy($node/node(), $xform)
            }
        else
            $node
};

(:~
 : Applies node transformations to nodes.
 :)
declare %private function xf:apply($nodes as item()*, $xform as map(*)*)
    as item()* {
    for $node in $nodes
    let $fn := xf:match($node, $xform)
    return
        if ($fn instance of function(*)) then
            xf:copy($fn($node), $xform)
        else if ($node instance of element()) then
            element { node-name($node) } {
                xf:apply($node/@*, $xform),
                xf:apply($node/node(), $xform)
            }
        else if ($node instance of document-node()) then
            document {
                xf:apply($node/node(), $xform)
            }
        else
            $node
};

(:~
 : Apply to be used from within templates.
 :)
declare function xf:apply($nodes as item()*)
    as element(xf:apply) {
    <xf:apply>{ $nodes }</xf:apply>
};

(:~
 : Look for nodes that match
 :)
declare %private function xf:select($nodes as item()*, $selectors as map(*)*)
    as item()* {
    for $node in $nodes
    let $fn := xf:match($node, $selectors)
    return
        if ($fn instance of function(*)) then
            xf:copy($fn($node), $selectors)
        else if ($node instance of element()) then
            xf:select($node/node(), $selectors)
        else if ($node instance of document-node()) then
            document {
                xf:select($node/node(), $selectors)
            }
        else
            ()
};

(:~
 : Find the first matching template for a node and return
 : it's node transformation function.
 :)
declare %private function xf:match($node as item(), $xform as map(*)*)
    as function(*)? {
    hof:until(
        function($templates as map(*)*) {
            let $is-match := head($templates)
            return
                empty($is-match) or
                not($is-match instance of map(*))
        },
        function($templates as map(*)*) {
            let $template := head($templates)
            return
                (
                    if ($template('match')($node)) then
                        $template('fn')
                    else
                        ()
                    ,
                    tail($templates)
                )
        },
        $xform
    )[1]
};

(:~
 : Returns true if the string expression matches the $node.
 :)
declare function xf:matches($node as item(), $expr as xs:string) as xs:boolean {
    typeswitch ($node)
    case element() return not($node/self::xf:*) and $expr = (name($node),'*')
    case attribute() return substring-after($expr, '@') = (name($node), '*')
    default return false()
};

(:~
 : Returns true if the css matcher matches the $node.
 :)
declare function xf:css-matches($node as item(), $css-matcher as map(*)) as xs:boolean {
    typeswitch ($node)
    case element()
    return
        not($node/self::xf:*) and $css-matcher('el') = (local-name($node),'*') and
        ( not($css-matcher('id')) or $css-matcher('id') = trace($node/@id,'ID: ') ) and
        ( not($css-matcher('att')) or $css-matcher('att') = $node/@*/local-name() )
    case attribute()
    return
        not($css-matcher('att')) or $css-matcher('att') = local-name($node)
    default return false()
};

(:~
 : Build a function that tests a node.
 :)
declare function xf:css-matcher($expr) {
    for $expr in tokenize($expr,'\s+')[1]
    let $parsed :=
        for $token in analyze-string($expr, '[@#.]?[^@#.]+')/fn:match
        return
            string($token)
    return
         map {
            'att': for $att in $parsed[starts-with(.,'@')][1] return substring-after($att,'@'),
            'el': $parsed[not(starts-with(.,'.') or starts-with(.,'#') or starts-with(.,'@'))],
            'class': for $cls in $parsed[starts-with(.,'.')] return substring-after($cls,'.'),
            'id': for $id in $parsed[starts-with(.,'#')][1] return substring-after($id,'#')
        }
};


[ignore] removed the svn:mime-type of application/octet-stream so this file is treated as text not binary, and tested to make sure mime-type is now treated as text not binary  [port of rev.14028]

git-svn-id: 1623499149f5af833cfad2814dce82e821210f6f@14029 8784284e-840f-0410-bd5a-a6a6012a0d1a

xquery version "1.0";

(:~ Basic XQuery equivalents of map, fold, and filter functions adapted from
 :  the standard library of the Scheme programming language.  Demonstrates the
 :  use of higher-order functions in eXist.
 :)

module namespace seq="http://exist-db.org/xquery/sequences";

import module namespace util="http://exist-db.org/xquery/util";

(:~ Applies $func to the items
 :  of two sequences and returns the results as
 :  a new sequence. Both input sequences should
 :  have the same length.
 :)
declare function seq:map($func as function, $seqA as item()*, $seqB as item()*)
as item()* {
	if(count($seqA) != count($seqB)) then
		error("The sequences passed to seq:map should have equal length.")
	else
    	for $a at $i in $seqA
    	let $b := $seqB[$i]
    	return
        	util:call($func, $a, $b)
};

(:~	Calls $func for all items in the sequence. For example, if
 :  the sequence is (1, 2, 3), $func will be called with arguments
 :  (1, 2) and (3, 3).
 :)
declare function seq:fold($func as function, $seq as item()*, $start as item()) {
	if(empty($seq)) then
		$start
	else
		seq:fold($func, remove($seq, 1), util:call($func, $start, $seq[1]))
};

(:~ Filters the passed sequence by calling $func for every
 :  item. All items for which $func returns true are copied
 :  to the output sequence, items for which it returns false
 :  are skipped.
 :)
declare function seq:filter($func as function, $seq as item()*)
as item()* {
	for $i in $seq
	return
		if(util:call($func, $i)) then
			$i
		else
			()
};


Avoids off-by-one error in page numbers during export

declare default element namespace "http://www.w3.org/1999/xhtml";
declare namespace xfdf="http://ns.adobe.com/xfdf/";

<xhtml>

Issue #	Section	Page	Author	Observation

{
for $h at $issue in //xfdf:highlight
let $page := $h/@page + 1 (: XFDF page numbers are 0-based :)
let $author := $h/@title
let $comment := $h/xfdf:contents/text()
let $rich_comment := $h/xfdf:contents-richtext/body/p/span/text()
let $comment := fn:concat($comment,$rich_comment)
return
{fn:string($issue)}	SECTION	{fn:string($page)}	{fn:string($author)}	{fn:string($comment)}

}

</xhtml>

declare default element namespace "http://www.w3.org/1999/xhtml";
declare namespace xfdf="http://ns.adobe.com/xfdf/";

<xhtml>

Issue #	Section	Page	Author	Observation

{
for $h at $issue in //xfdf:highlight
let $page := $h/@page
let $author := $h/@title
let $comment := $h/xfdf:contents/text()
let $rich_comment := $h/xfdf:contents-richtext/body/p/span/text()
let $comment := fn:concat($comment,$rich_comment)
return
{fn:string($issue)}	SECTION	{fn:string($page)}	{fn:string($author)}	{fn:string($comment)}

}

</xhtml>


Attempt to get comment from tokenising, using : as the separator

declare default element namespace "http://www.w3.org/1999/xhtml";
declare namespace xfdf="http://ns.adobe.com/xfdf/";

<xhtml>

Issue #	Section	Page	Author	Observation

{
  for $h at $issue in //xfdf:highlight
  let $page := fn:string($h/@page + 1) (: XFDF page numbers are 0-based :)
  let $author := fn:string($h/@title)
  let $comment := $h/xfdf:contents/text()
  let $rich_comment := $h/xfdf:contents-richtext/body/p/span/text()
  let $comment := fn:concat($comment,$rich_comment)
  let $tokenized_comment := fn:tokenize($comment, ":")
  let $comment := $tokenized_comment[1]
  let $section := fn:string($h/@subject) (: if it exists, it might include context :)
  let $section := fn:concat($section,fn:string($tokenized_comment[0]))
  return
{fn:string($issue)}	{$section}	{$page}	{$author}	{$tokenized_comment}

}

</xhtml>

declare default element namespace "http://www.w3.org/1999/xhtml";
declare namespace xfdf="http://ns.adobe.com/xfdf/";

<xhtml>

Issue #	Section	Page	Author	Observation

{
  for $h at $issue in //xfdf:highlight
  let $page := fn:string($h/@page + 1) (: XFDF page numbers are 0-based :)
  let $author := fn:string($h/@title)
  let $comment := $h/xfdf:contents/text()
  let $rich_comment := $h/xfdf:contents-richtext/body/p/span/text()
  let $comment := fn:concat($comment,$rich_comment)
  let $section := fn:string($h/@subject) (: if it exists, it might include context :)
  return
{fn:string($issue)}	{$section}	{$page}	{$author}	{$tokenized_comment}

}

</xhtml>


tweaking "Israili"

tweaking "Israili"

(: Creates search strings for macro-affiliations to use in Voyant Tools :)

(: The labels to append to each item in $search-strings :)
let $search-labels := (
'Muslim',
'Christian',
'Jewish',
'Zoroastrian',
'Sabian',
'Zindiq',
'Convert-to-Islam')

let $search-strings := (
'حنف*|زيدي*|السنّي*|أنصاري*|خارجي*|صحابي*|إمامي*|مالكي*|شافع*|معتزل*|صوفي*|حنبل*|مرجئ*|أشعر*|علوي*|شيع*|رافض*',
'مسيح*|نسطور*|نصران*|نصارى*|راهب*|سرياني*'
,'يهود*|إسرائيلي*'
,'مجوس*'
,'صابئ*'
,'زنديق*',
'اسلم*|*عتنق* الإسلام')

let $prefixes := ('ب','ل','ك','ف','و')

(: If turned on will only search for variants that include any shaddas in above strings. :)
let $require-existing-shadda := 1
(: If turned on will not allow any vowels provided in $search-strings to be absent. If off, will match any specified vowels as well as unvocalized versions, but not alternate vowels. :)
let $require-existing-vowels := 0
(: If turned on will add a search term with the definite article prefixed to the word. :)
let $add-optional-article := 1
(: If turned on will add attached prepositions and conjunctions as optional search strings. :)
let $add-optional-prefixes := 1

for $string at $i in $search-strings
let $existing-vowels :=
    if ($require-existing-vowels) then
        if ($require-existing-shadda) then
            replace(replace($string, '([ً-ِْ-ٖ])','ّ?$1ّ?'),'(ّّ\?([ً-ِْ-ٖ])ّ\?)|(ّ\?([ً-ِْ-ٖ])ّ\?ّ)','(ّ$2$4)|($2$4ّ)') (: optional shadda before / after required vowel, but keeps existing shaddas by replacing optional shaddas with required :)
        else
            replace(replace($string, '([ً-ِْ-ٖ])','ّ?$1ّ?'),'(ّّ\?)|(ّ\?ّ)','ّ?') (: optional shadda before / after required vowel, ignoring existing shaddas by removing duplicate shaddas :)
    else
        if ($require-existing-shadda) then
            replace(replace($string, '([ً-ِْ-ٖ])','$1?'),'(ّ([ً-ِْ-ٖ]\?))|(([ً-ِْ-ٖ]\?)ّ)','($2$4ّ)|(ّ$2$4)') (: optional existing vowel + required shadda on either side :)
        else
            replace(replace($string, '([ً-ٖ])','[ّ$1]*'),'ّ?(\[ّ[ً-ٖ]\]\*)ّ?','$1') (: optional existing vowel + optional shadda, in any order, replacing existing shaddas :)

let $add-vowels :=
    if ($require-existing-shadda) then
        replace(
            replace(
                replace(
                    $existing-vowels,
                    '([ء-ي])(ّ?)',
                    '$1$2[ً-ِْ-ٖ]*') (: Adds vowel wildcard after all consonants :)
                ,'\[ً-ِْ-ٖ\]\*([ً-ِْ-ٖ])'
                ,'$1'), (: Then removes wildcard if it is next to an existing vowel. :)
            '([ء-ي])\[ً-ِْ-ٖ\]\*',
            '$1[ً-ٖ]*') (: If there is no shadda normalizes to shadda-agnostic. :)
    else
        replace(
            replace(
                $existing-vowels,
                '([ء-ي])',
                '$1[ً-ٖ]*') (: Adds vowel wildcard after all consonants :)
            ,'\[ً-ٖ\]\*([\(ّ])'
            ,'$1') (: Then removes wildcard if it is next to an existing vowel-shadda combo. :)

let $remove-final-vowel := (: Removes final vowel because it confuses Voyant Tools. :)
    replace(
        replace($add-vowels,
        '\[ً-ٖ\]\*(\*?)($|\|)',
        '$1$2'),
    '\[ً-ِْ-ٖ\]\*(\*?)($|\|)',
    '$1$2')

let $add-article :=
    if ($add-optional-article) then
     (: Duplicates each segment of the search string, adding the article on the front of one.
     Then removes any back-to-back | characters created in the process. :)
        replace(
            replace($remove-final-vowel,'(.*?[\|$])','$1|الْ?$1'),
            '\|\|',
            '|')
    else $remove-final-vowel

let $add-prefixes :=
    if ($add-optional-prefixes) then
        let $prefixes-to-add := concat(string-join($prefixes,'?[ً-ِْ-ٖ]?'),'?[ً-ِْ-ٖ]?')
        (: Breaks string into segments by | character and adds prefix query to each string, then rejoins them. :)
        let $prefixes-added := concat($prefixes-to-add,string-join(tokenize($add-article,'\|'),concat('|',$prefixes-to-add)))
        (: Accounts for elided ا when preposition ل is added producing لل instead of لال.
        Duplicates the form with the article (if present) and creates an additional form with لل in place
        of the article. :)
        return replace(
            replace(
                $prefixes-added,
                concat('((',$prefixes-to-add,')(الْ\?)(.*?[\|$]))'),
                '$1|لِ?لْ?$4'),
            '\|\|',
            '|')
    else $add-article

let $normalize-alif := replace($add-prefixes,'ا','[آاإأ]')
let $normalize-ya := replace($normalize-alif,'ى','[يىئ]')
let $normalize-waw := replace($normalize-ya,'و','[وؤ]')

return (concat($search-labels[$i],': '),$normalize-waw,'
')

(: Creates search strings for macro-affiliations to use in Voyant Tools :)

(: The labels to append to each item in $search-strings :)
let $search-labels := (
'Muslim',
'Christian',
'Jewish',
'Zoroastrian',
'Sabian',
'Zindiq',
'Convert-to-Islam')

let $search-strings := (
'حنف*|زيدي*|السنّي*|أنصاري*|خارجي*|صحابي*|إمامي*|مالكي*|شافع*|معتزل*|صوفي*|حنبل*|مرجئ*|أشعر*|علوي*|شيع*|رافض*',
'مسيح*|نسطور*|نصران*|نصارى*|راهب*|سرياني*'
,'يهود*|إسرائيل*'
,'مجوس*'
,'صابئ*'
,'زنديق*',
'اسلم*|*عتنق* الإسلام')

let $prefixes := ('ب','ل','ك','ف','و')

(: If turned on will only search for variants that include any shaddas in above strings. :)
let $require-existing-shadda := 1
(: If turned on will not allow any vowels provided in $search-strings to be absent. If off, will match any specified vowels as well as unvocalized versions, but not alternate vowels. :)
let $require-existing-vowels := 0
(: If turned on will add a search term with the definite article prefixed to the word. :)
let $add-optional-article := 1
(: If turned on will add attached prepositions and conjunctions as optional search strings. :)
let $add-optional-prefixes := 1

for $string at $i in $search-strings
let $existing-vowels :=
    if ($require-existing-vowels) then
        if ($require-existing-shadda) then
            replace(replace($string, '([ً-ِْ-ٖ])','ّ?$1ّ?'),'(ّّ\?([ً-ِْ-ٖ])ّ\?)|(ّ\?([ً-ِْ-ٖ])ّ\?ّ)','(ّ$2$4)|($2$4ّ)') (: optional shadda before / after required vowel, but keeps existing shaddas by replacing optional shaddas with required :)
        else
            replace(replace($string, '([ً-ِْ-ٖ])','ّ?$1ّ?'),'(ّّ\?)|(ّ\?ّ)','ّ?') (: optional shadda before / after required vowel, ignoring existing shaddas by removing duplicate shaddas :)
    else
        if ($require-existing-shadda) then
            replace(replace($string, '([ً-ِْ-ٖ])','$1?'),'(ّ([ً-ِْ-ٖ]\?))|(([ً-ِْ-ٖ]\?)ّ)','($2$4ّ)|(ّ$2$4)') (: optional existing vowel + required shadda on either side :)
        else
            replace(replace($string, '([ً-ٖ])','[ّ$1]*'),'ّ?(\[ّ[ً-ٖ]\]\*)ّ?','$1') (: optional existing vowel + optional shadda, in any order, replacing existing shaddas :)

let $add-vowels :=
    if ($require-existing-shadda) then
        replace(
            replace(
                replace(
                    $existing-vowels,
                    '([ء-ي])(ّ?)',
                    '$1$2[ً-ِْ-ٖ]*') (: Adds vowel wildcard after all consonants :)
                ,'\[ً-ِْ-ٖ\]\*([ً-ِْ-ٖ])'
                ,'$1'), (: Then removes wildcard if it is next to an existing vowel. :)
            '([ء-ي])\[ً-ِْ-ٖ\]\*',
            '$1[ً-ٖ]*') (: If there is no shadda normalizes to shadda-agnostic. :)
    else
        replace(
            replace(
                $existing-vowels,
                '([ء-ي])',
                '$1[ً-ٖ]*') (: Adds vowel wildcard after all consonants :)
            ,'\[ً-ٖ\]\*([\(ّ])'
            ,'$1') (: Then removes wildcard if it is next to an existing vowel-shadda combo. :)

let $remove-final-vowel := (: Removes final vowel because it confuses Voyant Tools. :)
    replace(
        replace($add-vowels,
        '\[ً-ٖ\]\*(\*?)($|\|)',
        '$1$2'),
    '\[ً-ِْ-ٖ\]\*(\*?)($|\|)',
    '$1$2')

let $add-article :=
    if ($add-optional-article) then
     (: Duplicates each segment of the search string, adding the article on the front of one.
     Then removes any back-to-back | characters created in the process. :)
        replace(
            replace($remove-final-vowel,'(.*?[\|$])','$1|الْ?$1'),
            '\|\|',
            '|')
    else $remove-final-vowel

let $add-prefixes :=
    if ($add-optional-prefixes) then
        let $prefixes-to-add := concat(string-join($prefixes,'?[ً-ِْ-ٖ]?'),'?[ً-ِْ-ٖ]?')
        (: Breaks string into segments by | character and adds prefix query to each string, then rejoins them. :)
        let $prefixes-added := concat($prefixes-to-add,string-join(tokenize($add-article,'\|'),concat('|',$prefixes-to-add)))
        (: Accounts for elided ا when preposition ل is added producing لل instead of لال.
        Duplicates the form with the article (if present) and creates an additional form with لل in place
        of the article. :)
        return replace(
            replace(
                $prefixes-added,
                concat('((',$prefixes-to-add,')(الْ\?)(.*?[\|$]))'),
                '$1|لِ?لْ?$4'),
            '\|\|',
            '|')
    else $add-article

let $normalize-alif := replace($add-prefixes,'ا','[آاإأ]')
let $normalize-ya := replace($normalize-alif,'ى','[يىئ]')
let $normalize-waw := replace($normalize-ya,'و','[وؤ]')

return (concat($search-labels[$i],': '),$normalize-waw,'
')


Issue with namespaces:

Issue with namespaces:

<test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
with
for $case in fn:collection(  '/db/XQTS' )//*:test-case

yields in missing tests, and result="attribute is not filled in. This work around:

<test-suite-result>
with
for $case in fn:collection(  '/db/XQTS' )//test-case

is okay (but misses xmlns attribute of on root element)

svn path=/trunk/eXist-1.0/; revision=4037

declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename='results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml'" ) )

return
(: <test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> :)
<test-suite-result>
        <implementation name="{$product-version}" version="{$product-build}" anonymous-result-column="false">

                <organization name="eXist Open Source native XML database"  website="http://www.exist-db.org" anonymous="false"/>

                <submittor name="eXist XQTS testsuite runner" email="me@not.com"/>

                <description>

eXist is an Open Source native XML database featuring efficient,
                        index-based XQuery processing, automatic indexing, extensions for full-text
                        search,  XUpdate  support and tight integration with existing XML development tools.

                </description>

                <implementation-defined-items>

                </implementation-defined-items>

                <features>
{ for $feature in doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/*:features/*:feature
							return
							<feature name="{$feature/@name}" supported="true"/>
						}</features>

                <context-properties>

                </context-properties>

        </implementation>

        <syntax>XQuery</syntax>

        <test-run dateRun="{fn:current-dateTime()}">
                <test-suite version="{$test-suite}"/>
                <transformation>

No unusual transformations.

                </transformation>
                <comparison>

No unusual comparisons

                </comparison>
                <otherComments>

The test run took n seconds.

                </otherComments>
        </test-run>

{
		(: for $case in fn:collection(  '/db/XQTS' )//*:test-case :)
    for $case in fn:collection(  '/db/XQTS' )//test-case
    return <test-case name="{$case/@name}" result="{$case/@result}" />
}
</test-suite-result>

declare option exist:serialize "method=xml indent=yes";
declare option exist:output-size-limit "-1";
declare namespace response="http://exist-db.org/xquery/response";

let $product-version := util:system-property("product-version")
let $product-build := util:system-property("product-build")
let $test-suite := doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/@version
let $dummy := response:set-header("Content-Disposition", concat(
	"attachment; filename='results_XQTS-" , $test-suite , "_eXist-" ,
	$product-version , '_' , $product-build , ".xml'" ) )

return
<test-suite-result xmlns="http://www.w3.org/2005/02/query-test-XQTSResult"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

        <implementation name="{$product-version}" version="{$product-build}" anonymous-result-column="false">

                <organization name="eXist Open Source native XML database"  website="http://www.exist-db.org" anonymous="false"/>

                <submittor name="eXist XQTS testsuite runner" email="me@not.com"/>

                <description>

eXist is an Open Source native XML database featuring efficient,
                        index-based XQuery processing, automatic indexing, extensions for full-text
                        search,  XUpdate  support and tight integration with existing XML development tools.

                </description>

                <implementation-defined-items>

                </implementation-defined-items>

                <features>
{ for $feature in doc('/db/XQTS/XQTSCatalog.xml')/*:test-suite/*:features/*:feature
							return
							<feature name="{$feature/@name}" supported="true"/>
						}</features>

                <context-properties>

                </context-properties>

        </implementation>

        <syntax>XQuery</syntax>

        <test-run dateRun="{fn:current-dateTime()}">
                <test-suite version="{$test-suite}"/>
                <transformation>

No unusual transformations.

                </transformation>
                <comparison>

No unusual comparisons

                </comparison>
                <otherComments>

The test run took n seconds.

                </otherComments>
        </test-run>

{
    for $case in fn:collection(  '/db/XQTS' )//*:test-case
    return <test-case name="{$case/@name}" result="{$case/@result}"  />
}
</test-suite-result>