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

Re: A - B

Subject: Re: A - B
From: "Marrow" <marrow@xxxxxxxxxxxxxx>
Date: Thu, 22 Aug 2002 19:07:10 +0100
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@xxxxxxxxxxx>
To: mulberrytech <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Date: 22 August 2002 17:23
Subject:  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


Current Thread
  • A - B
    • pcoustillas - Thu, 22 Aug 2002 11:43:30 -0400 (EDT)
      • <Possible follow-ups>
      • Marrow - Thu, 22 Aug 2002 14:10:44 -0400 (EDT) <=
      • Marrow - Mon, 26 Aug 2002 06:03:02 -0400 (EDT)

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.