Re: [xsl] best practices for using XSLT modes

Subject: Re: [xsl] best practices for using XSLT modes
From: "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Dec 2019 15:00:06 -0000
Tweaked, now in 3.0 with expand-text=btrueb:

<xsl:template match="@val[. >= 0]">{ . }:
%3cxsl:template%20match=%22@val%5b0> > .]">{ . }: negative</xsl:template>

(Leaving aside discussion of the comparisons.)

In general I agree with everything thatbs been said in this thread. Whether
I would use templates this way, and whether in a mode, would probably depend
on the case and possibly on the phase of the moon.

Cheers, Wendell

From: Mukul Gandhi gandhi.mukul@xxxxxxxxx
Sent: Friday, December 6, 2019 12:43 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] best practices for using XSLT modes

Hi Eliot,

On Thu, Dec 5, 2019 at 8:21 PM Eliot Kimber
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx>> wrote:
but I would replace the choice that acts on different @val values with
templates applied to the @val attribute, i.e.:

        <xsl:template match="a">
          <val><xsl:apply-templates select="@val"/></val>

     <xsl:template match="@val[. ge 0]">
        <xsl:value-of select="@val || ': positive'"/>

     <xsl:template match="@val[. lt  0]">
        <xsl:value-of select="@val || ': negative"/>

Thanks for suggesting this. It looks intuitive.

Note that I handle the bug in the original in that it would produce no result
when @val is "0" (zero).

I actually, deliberately didn't include processing for the case @val being
zero (my XML & XSLT codes were merely examples for discussion, and were not a
real use case). But thanks, for pointing this fact.

The use of templates rather than xsl:choose makes the code cleaner, I think,
puts the focus at the template level on the @val attribute, which is the focus
of the business logic

I agree.

Mukul Gandhi
XSL-List info and
ZEUdRpzk2KiU%3D&reserved=0> (by email<>)

Current Thread