Re: [xsl] Creating strings with apos and replacing

Subject: Re: [xsl] Creating strings with apos and replacing
From: "dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 May 2025 20:08:59 -0000
I like this one

replace($input, '[^a-z0-9]+', '-', 'i')

more generl and avoids the problem all together ;-)

what does that 'i' and the end do? I thought replace only had 3 parameters.

I wasn't able to get any of the quote options in the replace to work, not sure what I'm doing wrong there, so this one gets the job done.

..dan
On 2025-05-13 12:19, Liam R. E. Quin liam@xxxxxxxxxxxxxxxx wrote:
On Tue, 2025-05-13 at 18:40 +0000, dvint@xxxxxxxxx wrote:
much working

<xsl:function name="ping:gen_id">
	<xsl:param name="INSTRING"/>
	<xsl:value-of select="translate(replace(lower-
case($INSTRING), ' ',
'_'),
	':()','')"/>
</xsl:function>

you could use translate() twice here of course. translate($input, ' ', '_')

often i use replace($input, '[^a-z0-9]+', '-', 'i')
for generating IDs (and then fix them up to be unique), since e.g.
allowing % or < or > or & can also cause interesting problems :)


select="translate($inputString,
&apos;&apos;, '')" />
\xA0\xA0\xA0\xA0 <xsl:value-of select="$outputString" />

Your problem here is after the XML parser converts &apos; to ' the XPath processor sees, translate($inputstring, '', '') which is not what you want at all.

select="translate($inputString, &quot;'&quot;, '')

will turn into
    translate($inputString, "'", '')
which is what i think you want.

Current Thread