Tweaked, now in 3.0 with expand-text=’true’:
<xsl:template match="@val[. >= 0]">{ . }:
positive</xsl:template><mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:template%20match=%22@val%5b0>
<mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:template%20match=%22@val%5b0>
<xsl:template
match="@val[0<mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:template%20match=%22@val%5b0>
.]">{ . }: negative</xsl:template>
(Leaving aside discussion of the comparisons.)
In general I agree with everything that’s 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(_dot_)mukul(_at_)gmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, December 6, 2019 12:43 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] best practices for using XSLT modes
Hi Eliot,
On Thu, Dec 5, 2019 at 8:21 PM Eliot Kimber
ekimber(_at_)contrext(_dot_)com<mailto:ekimber(_at_)contrext(_dot_)com>
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
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>
<xsl:template match="@val[. ge 0]">
<xsl:value-of select="@val || ': positive'"/>
</xsl:template>
<xsl:template match="@val[. lt 0]">
<xsl:value-of select="@val || ': negative"/>
</xsl:template>
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.
--
Regards,
Mukul Gandhi
XSL-List info and
archive<https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mulberrytech.com%2Fxsl%2Fxsl-list&data=02%7C01%7Cwendell.piez%40nist.gov%7Cf7b51036b56a490c942308d77a0f2813%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C1%7C637112077838001873&sdata=rBIoEd%2BCR91wIrvK6I1wn8oH5hpPeAxd5Jr1vwUKEps%3D&reserved=0>
EasyUnsubscribe<https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.mulberrytech.com%2Funsub%2Fxsl-list%2F3302254&data=02%7C01%7Cwendell.piez%40nist.gov%7Cf7b51036b56a490c942308d77a0f2813%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C1%7C637112077838006872&sdata=Px1KczNZVTbC4bOCgJvik51qhPp5bD6ZEUdRpzk2KiU%3D&reserved=0>
(by email<>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--