Subject: [xsl] emulating sprintf in XSLT From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 28 Aug 2022 23:06:04 -0000 |
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: <xsl:if test="$word-count > 0"> <xsl:variable name="minutes" select="xs:integer(ceiling($word-count div $words-per-minute))" as="xs:integer"/> <div> <strong>Estimated reading time:</strong> <xsl:value-of select="' %d %s' => replace('%d', string($minutes)) => replace('%s', if ($minutes = 1) then 'minute' else 'minutes')"/> </div> </xsl:if> Just wanted to share. Thanks! ----- Chris Papademetrious Tech Writer, Implementation Group (610) 628-9718 home office (570) 460-6078 cell
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] select the word to the le, Terry Ofner tdofner@ | Thread | Re: [xsl] emulating sprintf in XSLT, Liam R. E. Quin liam |
Re: [xsl] select the word to the le, Terry Ofner tdofner@ | Date | Re: [xsl] emulating sprintf in XSLT, Liam R. E. Quin liam |
Month |