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

Re: Calculations involving measurements with units

Subject: Re: Calculations involving measurements with units
From: "Paul A. Hoadley" <paulh@xxxxxxxxxxxxxx>
Date: Sun, 4 Jan 2004 08:24:44 +1030
xsl variables calculations
On Sat, Jan 03, 2004 at 12:43:23PM -0000, Michael Kay wrote:

> XSLT 2.0 lets you write stylesheet functions that can be called from
> within an XPath expression, which solves this problem.

Sounds ideal.

> In 1.0 you could try breaking the expression up by using variables,
> but of course these can't take arguments in the way that a template
> or function can.

I ended up writing a third template to handle calling the first two:

  <xsl:template name="divideDimension">
    <xsl:param name="dimension"/>
    <xsl:param name="divisor"/>
    <xsl:variable name="dimension-stripped">
      <xsl:call-template name="stripUnits">
        <xsl:with-param name="input" select="$dimension"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="result-stripped">
      <xsl:value-of select="$dimension-stripped div $divisor"/>
    </xsl:variable>
    <xsl:value-of select="$result-stripped"/>
    <xsl:call-template name="getUnits">
      <xsl:with-param name="input" select="$dimension"/>
    </xsl:call-template>
  </xsl:template>

Certainly this _works_ (in the limited number of circumstances I have
tested it), but is this the kind of code people are writing?  It just
seems rather verbose to me.  If that is just a limitation of XSLT 1.0,
then fine---but if it's verbose because I haven't seen a better way to
code it, let me know.  :-)


-- 
Paul.

mailto:paulh@xxxxxxxxxxxxxx
mailto:phoadley@xxxxxxxxxxxxxxxxxxxxx

 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.