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

Re: performing calculations with variables / params in

Subject: Re: performing calculations with variables / params in FO using certain units (mm, px, etc)
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 30 Oct 2003 21:15:28 +0100
xsl calculations
> If I am specifying those variables as, 300mm and 200mm respectively I
> suppose there will be a problem in trying to subtract them with the
> units present.
>
> Is there some way to specify a particular UNIT to be used all over so
> that I can specify those values without the units appended (makes
> subtraction easy)?
>
> Is there a way to have this subtraction performed with the units
> present,  without having to write intensive string parsing functions to
> separate the values & units?

Yes. Below is a transformation, which uses the "transform-and-sum" template
from FXSL:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func-transform="f:func-transform"
exclude-result-prefixes="xsl func-transform"
>
   <xsl:import href="transform-and-sum.xsl"/>

   <!-- to be applied on testTransform-and-sum3.xml -->

   <xsl:output method="text"/>

   <func-transform:func-transform/>

    <xsl:template match="/">
      <xsl:call-template name="transform-and-sum">
        <xsl:with-param name="pFuncTransform"
                        select="document('')/*/func-transform:*[1]"/>
        <xsl:with-param name="pList" select="//freespace"/>
      </xsl:call-template>
    </xsl:template>

    <xsl:template match="func-transform:*">
      <xsl:param name="arg" select="0"/>
      <xsl:value-of select="translate($arg, translate($arg, '0123456789',
''), '')"/>
    </xsl:template>

</xsl:stylesheet>

When applied on this source.xml:

<disks>
  <disk>
    <freespace>1235MB</freespace>
  </disk>
  <disk>
    <freespace>40MB</freespace>
  </disk>
  <disk>
    <freespace>75MB</freespace>
  </disk>
</disks>

the wanted result is produced:
1350


Another solution will consume all digits befor a non-digit is encountered -- 
this will use the "str-take-while" template.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.