xsl-list
[Top] [All Lists]

Re: [xsl] best practices for using XSLT modes

2019-12-05 23:42:34
Hi Eliot,

On Thu, Dec 5, 2019 at 8:21 PM Eliot Kimber ekimber(_at_)contrext(_dot_)com <
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: 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
--~--
<Prev in Thread] Current Thread [Next in Thread>