[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how to show 0.00 when no element is present

Subject: Re: how to show 0.00 when no element is present
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Wed, 25 Oct 2000 23:03:25 -0700
xsl test element 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=".&gt;0">
      <Font color="green">
        <xsl:value-of select="format-number(.,'##.##')"/>
      </Font>
    </xsl:when>
    <xsl:when test=".&lt;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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.