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

Re: WG: RPN calculator

Subject: Re: WG: RPN calculator
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 2 May 2002 13:47:40 +0100
how to calculate mode
Hi Costantino,

> Regarding Jeni's answer, actually I do not understand the purpose of
> using a mode (besides learning something new for me...). And I tried
> it, but it doesn't work, I think because it enters the multiply or
> sum templates without the "calculate" mode.

Yes, sorry -- I should have said "To do the calculation, apply
templates to the equation in 'calculate' mode." So do something like:

<xsl:template match="/">
  <xsl:apply-templates mode="calculate" />
</xsl:template>

I usually use modes when I want to do something with a bit of XML that
isn't simply giving the textual output from that XML. In your case,
for example, you might want to actually print out the equation with
some normal templates like:

<xsl:template match="multiply">
  <xsl:text>(</xsl:text>
  <xsl:apply-templates select="arg1" />
  <xsl:text> * </xsl:text>
  <xsl:apply-templates select="arg2" />
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="sum">
  <xsl:text>(</xsl:text>
  <xsl:apply-templates select="arg1" />
  <xsl:text> + </xsl:text>
  <xsl:apply-templates select="arg2" />
  <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="text()">
  <xsl:value-of select="normalize-space()" />
</xsl:template>

And then have the result of the stylesheet actually be governed
through:

<xsl:template match="/">
  <xsl:apply-templates />
  <xsl:text> = </xsl:text>
  <xsl:apply-templates mode="calculate" />
</xsl:template>

That's my excuse for using a mode, anyway.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.