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]

how to show 0.00 when no element is present


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

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