Skip to content

Commit

Permalink
[MOD] treat variable nodes correctly in compiled schemas; only append…
Browse files Browse the repository at this point in the history
… data() to value-of results of type node()
  • Loading branch information
AndrewSales committed May 20, 2023
1 parent d2bc052 commit 0568274
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions compile.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ declare function compile:assertion-message-content($content as node()*)
then ('{(' || $compile:RULE_CONTEXT || ')/' || $node/@path || '}')
else '{name(' || $compile:RULE_CONTEXT || ')}'
case element(sch:value-of)
return ('{(' || $compile:RULE_CONTEXT || ')/' || $node/@select || '/data()}')
return ('{let $result := (' || $compile:RULE_CONTEXT || ')/' || $node/@select
|| ' return if($result instance of node()) then $result/data() else $result}')
case element(sch:emph)
return output:assertion-child-elements($node)
case element(sch:dir)
Expand All @@ -222,7 +223,7 @@ as xs:string?
if($var/@value instance of xs:anyAtomicType+)
then $var/@value/data() => util:escape()
else
$compile:INSTANCE_DOC || '/(' || $var/@value => util:escape() || ')'
$compile:INSTANCE_DOC || '/(' || util:variable-value($var) || ')'
)
|| ';'
)
Expand Down
3 changes: 2 additions & 1 deletion test/test-compile.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ declare %unit:test function _:properties()
)
let $result := xquery:eval(
$compiled,
map{$_:DOC_PARAM:document{<foo/>}}
map{$_:DOC_PARAM:document{<foo/>}},
map{'pass':'true'}
)
return (
unit:assert-equals(
Expand Down
2 changes: 1 addition & 1 deletion utils.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ as xs:string
: current context. If no value attribute is specified, the value of the
: attribute is the element content of the let element."
:)
declare %private function util:variable-value($var as element(sch:let))
declare function util:variable-value($var as element(sch:let))
as xs:string
{
if($var/@value) then $var/@value/data() => util:escape() else serialize($var/*)
Expand Down

0 comments on commit 0568274

Please sign in to comment.