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]
Other format: [Raw text]

Re: A - B


Hi,

If you wanted missing values to default to zero you could use sum(), e.g.

== XML1 ================================
<?xml version="1.0"?>
<root>
  <B>3</B>
</root>
== end of XML1 ===========================

== XSL1 =================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:value-of select="sum(root/A[1]) - sum(root/B[1])"/>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 ============================

or if the values are optional and, if present, might also contain non-numeric
values to be defaulted to zero, e.g.

== XML2 ================================
<?xml version="1.0"?>
<root>
  <A>xyz</A>
  <B>3</B>
</root>
== end of XML2 ===========================

== XSL1 =================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>
<xsl:template match="/">
  <xsl:value-of select="sum(root/A[1][number(.) = number(.)]) -
sum(root/B[1][number(.) = number(.)])"/>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 ============================

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator



-----Original Message-----
From: pcoustillas <pcoustillas@perinfo.com>
To: mulberrytech <xsl-list@lists.mulberrytech.com>
Date: 22 August 2002 17:23
Subject: [xsl] A - B


>hi, how could i do A-B when A or B does not exist or is absent...
>because without a test i recieve "NaN". Thanks.
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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]