Re: How do you use nillable ?

Hi Chagit,

> I do not manage to find a working example of the use of nillable.
> What is necessary to do on the xsl side? And what on the xml side?

You can declare that an element is nillable -- by adding a nillable
attribute to its element declaration:

<xs:element name="date" nillable="true" type="xs:date" />

Being nillable means that an instance of the element can be valid even
if it doesn't have any content, as long as it has an xsi:nil attribute
on it, with a value equal to 'true'. So for example:

<date xsi:nil="true" />

is valid, even though:

<date />

wouldn't be.

XSLT 1.0 doesn't have any access to schema information (well, aside
from going looking at the schema document itself using the document()
function). As far as XSLT is concerned, the xsi:nil attribute is just
like any other attribute. So if you're using xsi:nil in your instance
document, you can check that it's there with a true value using XSLT:

<xsl:template match="date">
  <xsl:choose>
    <xsl:when test="@xsi:nil = 'true' or @xsi:nil = '1'">NIL</xsl:when>
    <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
  </xsl:choose>
</xsl:template>

In XSLT 2.0 (or technically XPath 2.0), a nil value is an empty
sequence whereas an empty value is an empty string, so you can tell
the difference that way.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Wednesday, 1 May 2002 05:44:04 UTC