[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|