[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Calculations involving measurements with units


Subject: Re: [xsl] Calculations involving measurements with units
From: "Paul A. Hoadley" <paulh@xxxxxxxxxxxxxx>
Date: Sun, 4 Jan 2004 08:24:44 +1030

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
Keywords