This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: how to show 0.00 when no element is present
Russ Holmes wrote:
> ..and I get a blank page...what I really want is a a bunch of 0.00's....but
> how can I apply the template which tests the @val1,@val2,@val3 attributes
> and applies the appropriate formatting, if I don't have those elements
> present in the xml??
Here's the solution I came up with. The PageData template is always
executed and provides the outer HTML. If there are no rows, the
xsl:otherwise emits the 0.00 field values. Otherwise, we
apply-templates to the attributes as before.
You don't need to replicate the built-in templates that XSLT
automatically provides so I removed them.
HTH,
Gary
<xsl:stylesheet version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:z="#RowsetSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="PageData">
<HTML>
<HEAD/>
<BODY>
List of Values
<br/>
<xsl:choose>
<xsl:when test="//z:row">
<xsl:apply-templates select="//z:row"/>
</xsl:when>
<xsl:otherwise>
0.00<br/>0.00<br/>0.00
</xsl:otherwise>
</xsl:choose>
<br/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="z:row">
<xsl:apply-templates select="@val1"/>
<br/>
<xsl:apply-templates select="@val2"/>
<br/>
<xsl:apply-templates select="@val3"/>
</xsl:template>
<xsl:template match="@*">
<xsl:choose>
<xsl:when test=".>0">
<Font color="green">
<xsl:value-of select="format-number(.,'##.##')"/>
</Font>
</xsl:when>
<xsl:when test=".<0">
<Font color="red">
<xsl:value-of select="format-number(.,'##.##')"/>
</Font>
</xsl:when>
<xsl:otherwise>
0.00
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list