Re: [xsl] emulating sprintf in XSLT

Subject: Re: [xsl] emulating sprintf in XSLT
From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Aug 2022 07:55:52 -0000
Thanks Liam, that's even more direct and efficient!

 - Chris


-----Original Message-----
From: Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Sunday, August 28, 2022 7:52 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] emulating sprintf in XSLT

On Sun, 2022-08-28 at 23:06 +0000, Chris Papademetrious
christopher.papademetrious@xxxxxxxxxxxx wrote:
> Hi everyone,
>
> If you need sprintf()-like functionality in XSLT, one approach is to
> use the arrow (=>) operator to apply a series of replace()
> operations:

Another, in XSLT 3, is to use text value templates:
  <p><h4>Estimated reading time:</h4>
  <p>{$minutes} {if ($minutes eq 1) then 'minute' else 'minutes'}</p>

This requires expand-text="yes" on an XSLT element ancestor, or
xsl:expand-text="yes" on a direct element contstructor (like the p element in
the example above).

liam

--
Liam Quin - paligo.net, delightfulcomputing.com Cancer gofundme
https://www.gofundme.com/f/5u9v7-every-little-helps
Vintage pictures & texts https://www.fromoldbooks.org/

Current Thread