Hi Eliot,
On Thu, Dec 5, 2019 at 8:21 PM Eliot Kimber ekimber@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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
|