This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: WG: 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]