Last active
March 11, 2019 03:22
-
-
Save micheee/b16586464b895f08ddfb to your computer and use it in GitHub Desktop.
fn:nilled.xq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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