Skip to content

Commit

Permalink
[MOD] name/@path; value-of/@select, re #21
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Aug 7, 2023
1 parent b16c96c commit f48b81c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
52 changes: 40 additions & 12 deletions svrl.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ declare function output:assertion-message(
$context as map(*)
)
{
if($context?dry-run eq 'true')
then output:assertion-message-content(
$assertion/node(),
$prolog,
$rule-context,
$context
)
else
element{
QName("http://purl.oclc.org/dsdl/svrl",
if($assertion/self::sch:assert) then 'failed-assert' else 'successful-report')}
Expand Down Expand Up @@ -109,27 +117,32 @@ declare function output:assertion-message-content(
$rule-context as node(),
$context as map(*)
)
as item()*
{
if($context?dry-run eq 'true')
then
for $node in $content/(self::sch:name|self::sch:value-of)
return
typeswitch($node)
case element(sch:name)
return if($node/@path)
then output:name-value-of($node/@path, $prolog, $rule-context, $context)
else name($rule-context)
case element(sch:value-of)
return output:name-value-of($node/@select, $prolog, $rule-context, $context)
default return ()
else
<svrl:text>{(:TODO attributes:)
for $node in $content
return
typeswitch($node)
case element(sch:name)
return if($node/@path)
then utils:eval(
$prolog || $node/@path,
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true'},
$node/@path
)
then output:name-value-of($node/@path, $prolog, $rule-context, $context)
=> string()
else name($rule-context)
case element(sch:value-of)
return utils:eval(
$prolog || $node/@select,
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true'},
$node/@select
)
return output:name-value-of($node/@select, $prolog, $rule-context, $context)
=> string()
case element(sch:emph)
return output:assertion-child-elements($node)
Expand All @@ -139,4 +152,19 @@ declare function output:assertion-message-content(
return output:assertion-child-elements($node)
default return $node
}</svrl:text>
};

declare function output:name-value-of(
$attr as attribute(),
$prolog as xs:string?,
$rule-context as node(),
$context as map(*)
)
{
utils:eval(
$prolog || $attr,
map:merge((map{'':$rule-context}, $context?globals)),
map{'dry-run':$context?dry-run},
$attr
)
};
2 changes: 1 addition & 1 deletion utils.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ declare function utils:eval(
catch * {
<svrl:failed-assert err:code='{$err:code}' location='{$node/path()}'
test='xquery:parse(.)'>
<svrl:text>{$err:description} {' @'||$node/name()}='{$node/data()}'</svrl:text></svrl:failed-assert>
<svrl:text>{$err:description}{' @'||$node/name()}='{$node/data()}'</svrl:text></svrl:failed-assert>
})
else xquery:eval($query, $bindings, map{'pass':'true'})
};

0 comments on commit f48b81c

Please sign in to comment.