Re: [xsl] emulating sprintf in XSLT

Subject: Re: [xsl] emulating sprintf in XSLT
From: "Wegmann, Frank frank.wegmann@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Aug 2022 06:44:27 -0000
I guess, using text value templates is a better choice regarding performance,
or...?

Frank

-----Original Message-----
From: Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, 29 August 2022 01:53
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://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gofundm
e.com%2Ff%2F5u9v7-every-little-helps&amp;data=05%7C01%7Cfrank.wegmann%40softw
areag.com%7C3e5e2ac1c08e4e3b35d708da89506035%7Cd9662eb9ad984e74a8a204ed5d544d
b6%7C1%7C0%7C637973275564376684%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=CaZdn
DkfcyQY2gZMQcRtD3r7W0nh%2B%2BqaG7DDVOaUOyw%3D&amp;reserved=0
Vintage pictures & texts
https://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.fromold
books.org%2F&amp;data=05%7C01%7Cfrank.wegmann%40softwareag.com%7C3e5e2ac1c08e
4e3b35d708da89506035%7Cd9662eb9ad984e74a8a204ed5d544db6%7C1%7C0%7C63797327556
4532784%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6I
k1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=LYTuSNv8agemhvSyZY2xDQMV2yTu4
qSH7WZNljO71lk%3D&amp;reserved=0



Software AG b Sitz/Registered office: UhlandstraCe 12, 64297 Darmstadt,
Germany b Registergericht/Commercial register: Darmstadt HRB 1562 -
Vorstand/Management Board: Sanjay Brahmawar (Vorsitzender/Chairman), Dr. Elke
Frank, Dr. Matthias Heiden, Dr. Stefan Sigg, Dr. Benno Quade, Joshua Husk -
Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Christian Lucas -
https://www.softwareag.com

Current Thread