AW: WG: [xsl] RPN calculator

Subject: AW: WG: [xsl] RPN calculator
From: Costantino.Sertorio@xxxxxxxxxxxx
Date: Thu, 2 May 2002 14:59:05 +0200
Understood!
Thank you very much for the explanation,

Costantino

-----Ursprüngliche Nachricht-----
Von: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Gesendet am: Donnerstag, 2. Mai 2002 14:48
An: Costantino.Sertorio@xxxxxxxxxxxx
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: Re: WG: [xsl] RPN calculator

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