|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Calculations involving measurements with units
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








