Skip to content

Instantly share code, notes, and snippets.

@micheee
Last active March 11, 2019 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micheee/b16586464b895f08ddfb to your computer and use it in GitHub Desktop.
Save micheee/b16586464b895f08ddfb to your computer and use it in GitHub Desktop.
fn:nilled.xq
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
(:
Tries to mimic http://www.w3.org/TR/xpath-functions-30/#func-nilled
If $arg is the empty sequence, the function returns the empty sequence.
:)
declare function local:nilled($arg as node()?) as xs:boolean? {
if(empty($arg)) then ()
else (
not($arg/(text()|node())) and $arg/@xsi:nil eq "true"
)
};
let $in-xml :=<root >
<child>12</child>
<child xsi:nil="true"></child> <!-- true -->
<child xsi:nil="true">a</child> <!-- false, this is non valid XML ;-) -->
<child></child> <!-- false -->
<child/> <!-- false -->
<child xsi:nil="false"></child> <!-- false -->
</root>
return $in-xml//child ! <result>
{ local:nilled(.) } : { . }
</result>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment