Name
[2.0 – Schema] nilled()
Returns true if a
given element has been nilled, false otherwise. If the argument is not
an element, nilled()
returns the empty sequence.
Syntax
xs:boolean?nilled(node()?)
Inputs
A node.
Outputs
If the given node has been nilled (meaning it has the
attribute xsi:nil="true"), this
function returns true;
otherwise it returns false.
Calling nilled() with the
empty sequence returns the empty sequence.
Note
The nilled()
function works only with schema-aware processors, and only if
the document is using a schema. The schema can be imported into
the stylesheet with <xsl:import-schema>, or the XML
document can use the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes. If no schema
is associated with the XML document, all of the nodes in the
document will have datatypes, and the nilled() function will always
return false.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 2, “Accessors.”
Example
Here is a very short XML document that we’ll use to
demonstrate the nilled()
function:
<?xml version="1.0" encoding="utf-8"?> <!-- person.xml --> <person xmlns="http://www.oreilly.com/xslt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oreilly.com/xslt person.xsd"> <name>Doug Tidwell</name> <age>42</age> <birthday xsi:nil="true"/> </person>
Notice that we’ve defined a schema,
person.xsd. That schema says that the
<birthday> element can be
nilled:
<?xml version="1.0" encoding="UTF-8"?>
<!-- person.xsd --> <xs:schema ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access