This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: outputing a non existant element.


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]