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

how to show 0.00 when no element is present

Subject: how to show 0.00 when no element is present
From: "Russ Holmes" <rholmes@xxxxxxxxx>
Date: Wed, 25 Oct 2000 11:01:27 +1300
xslt no element
I have XML generated by VB COM - persisting ADO recordsets eg-...

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="test.xsl"?>
<PageData>

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"

xmlns:z="#RowsetSchema">
 <s:Schema id="RowsetSchema">
  <s:ElementType name="row" content="eltOnly" rs:updatable="true">
   <s:AttributeType name="val1" rs:number="1" rs:nullable="true"
rs:basetable="inqsnap" rs:basecolumn="val1">
    <s:datatype dt:type="number" rs:dbtype="numeric" dt:maxLength="19"
rs:scale="2" rs:precision="38" rs:fixedlength="true"/>
   </s:AttributeType>
   <s:AttributeType name="val2" rs:number="2" rs:nullable="true"
rs:basetable="inqsnap" rs:basecolumn="val2">
    <s:datatype dt:type="number" rs:dbtype="numeric" dt:maxLength="19"
rs:scale="2" rs:precision="38" rs:fixedlength="true"/>
   </s:AttributeType>
   <s:AttributeType name="val3" rs:number="3" rs:nullable="true"
rs:basetable="inqsnap" rs:basecolumn="val3">
    <s:datatype dt:type="number" rs:dbtype="numeric" dt:maxLength="19"
rs:scale="2" rs:precision="38" rs:fixedlength="true"/>
   </s:AttributeType>
  </s:ElementType>
 </s:Schema>
 <rs:data>
  <z:row val1="17422.46755" val2="-1847.4670" val3="" />
 </rs:data>
</xml>
</PageData>

I want to show positive values in green, negative in red and null, 0 or
missing values as 0.00

I have the red/green thing no probs..

<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>

<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

<xsl:template match="/"><HTML>
  <HEAD/>

 <BODY>
  List of Values
  <br/>
    <xsl:apply-templates select="//@val1"/>
 <br/>
    <xsl:apply-templates select="//@val2"/>
 <br/>
    <xsl:apply-templates select="//@val3"/>
 <br/>
  </BODY>
</HTML></xsl:template>

<xsl:template match="@val1|@val2|@val3">
<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>

....but then if my COM returns an empty recordset, the xml looks like;

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="test.xsl"?>
<PageData>

</PageData>

..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??

Thanks

Russ



 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.