-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxqs.xqm
83 lines (76 loc) · 2.35 KB
/
xqs.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module namespace xqs = 'http://www.andrewsales.com/ns/xqs';
import module namespace context = 'http://www.andrewsales.com/ns/xqs-context' at
'context.xqm';
import module namespace eval = 'http://www.andrewsales.com/ns/xqs-evaluate' at
'evaluate.xqm';
import module namespace compile = 'http://www.andrewsales.com/ns/xqs-compile' at
'compile.xqm';
import module namespace ie = 'http://www.andrewsales.com/ns/xqs-include-expand'
at 'include-expand.xqm';
declare namespace sch = "http://purl.oclc.org/dsdl/schematron";
(:~ Validates a document against a Schematron schema, without applying a phase.
: @param instance the instance document
: @param schema the Schematron schema
:)
declare function xqs:validate(
$instance as node(),
$schema as element(sch:schema)
)
{
xqs:check-query-binding($schema),
eval:schema($instance, ie:include-expand($schema), '')
};
(:~ Validates a document against a Schematron schema, applying an optional phase.
: @param instance the instance document
: @param schema the Schematron schema
: @param phase the active phase
:)
declare function xqs:validate(
$instance as node(),
$schema as element(sch:schema),
$phase as xs:string
)
{
xqs:check-query-binding($schema),
eval:schema($instance, ie:include-expand($schema), $phase)
};
(:~ Compiles a Schematron schema, without applying a phase.
: @param schema the Schematron schema
:)
declare function xqs:compile(
$schema as element(sch:schema)
)
as xs:string
{
xqs:check-query-binding($schema),
compile:schema(ie:include-expand($schema), '')
};
(:~ Compiles a Schematron schema, applying an optional phase.
: @param schema the Schematron schema
: @param phase the active phase
:)
declare function xqs:compile(
$schema as element(sch:schema),
$phase as xs:string
)
as xs:string
{
xqs:check-query-binding($schema),
compile:schema(ie:include-expand($schema), $phase)
};
(:~ Mandate one of the reserved names for the XQuery query language binding. :)
declare function xqs:check-query-binding($schema as element(sch:schema))
{
let $query-binding := $schema/@queryBinding
return
if (exists($query-binding))
then
if(lower-case($query-binding) = ('xquery', 'xquery3', 'xquery31'))
then ()
else error(
xs:QName('xqs:invalid-query-binding'),
'query language binding must be XQuery',
$schema/@queryBinding
)
else()
};