Subject: Re: [xsl] best practices for using XSLT modes From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 6 Dec 2019 19:46:15 -0000 |
Sure, but this will have to be <xsl:template match="@val[. >= 0]">{ . || ': positive'}</xsl:template> or the slightly more explicit <xsl:template match="@val[. >= 0]">{ string(.) || ': positive'}</xsl:template> since by matching the attribute, we have changed the context of XPath evaluation. Of course it could all be rearranged as well. I might prefer templates in a mode that return nothing label, then use a generic match on @val that emits the value and performs the concatenation, calling the moded template for the label. Cheers, Wendell On Fri, Dec 6, 2019 at 1:26 PM Eliot Kimber ekimber@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Whiltespace is definitely a concern. > > I especially dislike things like: > > <xsl:value-of>, <xsl:value-of> (would be even worse if that was just xsl:template instead of xsl:value-of). It's easy for fiddly bits to be misread or lost in code cleanup or whatever. > > So I tend to prefer either xsl:text or xsl:value-of with concat() or, XPath 3, "||" operator. > > Using a text value template as the sole value of a template I think will satisfy my need for explicitness: > > <xsl:template match="@val[. >= 0]">{@val || ': positive'}</xsl:template> > > That makes the string construction intent clear while avoiding all unnecessary markup and any unintended whitespace. > > Cheers, > > E. > -- > Eliot Kimber > http://contrext.com > > > o;?On 12/6/19, 11:13 AM, "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Probably Eliot has in mind unintended whitespace in the results (heh). > > > > Whitespace. The bane of empires. > > > > (But oof. I can see I need to do a better job cleaning up after this email client.) > > > > Cheers, Wendell > > > > -----Original Message----- > > From: Eliot Kimber ekimber@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > > Sent: Friday, December 6, 2019 10:54 AM > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > Subject: Re: [xsl] best practices for using XSLT modes > > > > I don't like having literal text as direct children of <xsl:template>--too many opportunities for unintended results, so I would use xsl:text where Wendel has not: > > > > <xsl:template match="@val[. >= 0]"><xsl:text>{ . }: positive</xsl:text></xsl:template> > > > > At which point the verbosity is essentially equal my original using <xsl:value-of> but maybe a little cleaner. > > > > Cheers, > > > > E. > > > > -- > > Eliot Kimber > > https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fcontrext.com &data=02%7C01%7Cwendell.piez%40nist.gov%7C40a5f09f3615437cb95c08d77a648c7 f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C1%7C637112444592037420&sdata=L UMFZBa4Z5OqDN0xSmeW3hTEf27CypRUpldnEbEW%2FS0%3D&reserved=0 > > > > > > o;?On 12/6/19, 9:00 AM, "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > > > Tweaked, now in 3.0 with expand-text=btrueb: > > > > <xsl:template match="@val[. >= 0]">{ . }: positive</xsl:template> <mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:templa te%20match=%22@val%5b0> > > <mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:templa te%20match=%22@val%5b0> > > <xsl:template match="@val[0 <mailto:%22%3e%7b%20.%20%7d:%20positive%3c/xsl:template%3e%0d%0d%3cxsl:templa te%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 <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > > > > > > 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 > > > > ekimber@xxxxxxxxxxxx <mailto: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 > > > > > > > > > > XSL-List > > > > info and archive <https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mulberr ytech.com%2Fxsl%2Fxsl-list&data=02%7C01%7Cwendell.piez%40nist.gov%7C40a5f 09f3615437cb95c08d77a648c7f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C1%7C6371 12444592037420&sdata=zb2EUsZVWDmrzTRxw8pw9u2S%2B3kyXnYdjNs1VNceIqI%3D& ;reserved=0> > > EasyUnsubscribe <https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.mulbe rrytech.com%2Funsub%2Fxsl-list%2F3302254&data=02%7C01%7Cwendell.piez%40ni st.gov%7C40a5f09f3615437cb95c08d77a648c7f%7C2ab5d82fd8fa4797a93e054655c61dec% 7C1%7C1%7C637112444592037420&sdata=pcdD41LDdZU0bGK9Nxvm9EvXDEz7ut2bMze79V wsgE4%3D&reserved=0> > > > > (by email <>) > > > > > > > > > > > > XSL-List info and archive <https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mulberr ytech.com%2Fxsl%2Fxsl-list&data=02%7C01%7Cwendell.piez%40nist.gov%7C40a5f 09f3615437cb95c08d77a648c7f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C1%7C6371 12444592037420&sdata=zb2EUsZVWDmrzTRxw8pw9u2S%2B3kyXnYdjNs1VNceIqI%3D& ;reserved=0>EasyUnsubscribe <https://gcc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.mulbe rrytech.com%2Funsub%2Fxsl-list%2F1278982&data=02%7C01%7Cwendell.piez%40ni st.gov%7C40a5f09f3615437cb95c08d77a648c7f%7C2ab5d82fd8fa4797a93e054655c61dec% 7C1%7C1%7C637112444592037420&sdata=O%2FaPBHUdF4pdLCK4UfXIcPZgLLf0HCyr3Szc 7b0kFrU%3D&reserved=0> > > (by email <>) > > > > > > > > > > > > > -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] best practices for using , Eliot Kimber ekimber | Thread | Re: [xsl] best practices for using , BR Chrisman brchrism |
Re: [xsl] How to call an XSLT funct, Martin Honnen martin | Date | Re: [xsl] How to call an XSLT funct, Liam R. E. Quin liam |
Month |