XSLT Reference
nilled()
Returns true if an element node is schema-validated and marked as nilled with xsi:nil="true", otherwise returns false.
nilled(node?)Description
nilled() returns xs:boolean true if the argument is an element node that has been schema-validated and has its nilled property set — i.e., the element carries xsi:nil="true" and its schema type permits nilling.
For elements that have not been schema-validated, or for non-element nodes, the function returns false. If the argument is the empty sequence, the empty sequence is returned.
In practice, nilled() is used with schema-aware processors (such as Saxon-EE) to distinguish a genuinely absent value (xsi:nil="true") from an element that is simply empty.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
node | node()? | No | The node to test. Defaults to the context node. |
Return value
xs:boolean? — true if the element is nilled, false if it is not, or the empty sequence if the argument is the empty sequence.
Examples
Filter out nilled elements
Input XML (schema-validated):
<?xml version="1.0" encoding="UTF-8"?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<employee id="1"><name>Alice</name></employee>
<employee id="2" xsi:nil="true"/>
<employee id="3"><name>Charlie</name></employee>
</employees>
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/employees">
<active-employees>
<xsl:copy-of select="employee[not(nilled(.))]"/>
</active-employees>
</xsl:template>
</xsl:stylesheet>
Output:
<active-employees>
<employee id="1"><name>Alice</name></employee>
<employee id="3"><name>Charlie</name></employee>
</active-employees>
Report nil status of each element
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/employees">
<report>
<xsl:for-each select="employee">
<entry id="{@id}" nilled="{nilled(.)}"/>
</xsl:for-each>
</report>
</xsl:template>
</xsl:stylesheet>
Notes
nilled()only returnstruefor schema-validated elements withxsi:nil="true"and a nillable type in the schema. Without schema validation, it always returnsfalse.- For non-schema-aware processing, checking
@xsi:nil = 'true'directly is a common alternative. - This function is defined in XPath 2.0 and is not available in XSLT 1.0.