This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: outputing a non existant element.
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] outputing a non existant element.
- From: "Michael Kay" <mhkay at iclway dot co dot uk>
- Date: Wed, 12 Sep 2001 20:54:31 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
> i have one optional element in my schema-file say:
> <fruit>orange</fruit>.The default value of fruit is
> "apple".I would like to have a xslt-transformation
> which gives me the content of the fruit element if it
> appears in the xml-file or its default value if it
> doesn't appear.
The simple answer is
<xsl:choose>
<xsl:when test="fruit"><xsl:value-of select="fruit"/></xsl:when>
<xsl:otherwise>apple</xsl:otherwise>
</xsl:choose>
If you prefer brevity to clarity, you can write
<xsl:value-of select="concat(fruit, substring('apple', 1, not(fruit)*5)
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list