Vam
Vam

Reputation: 11

How to convert Single quote to Apostrophe(Curled Quote) in XsLT

I am trying to translate the below(Single Quote to Apostrophe):

Input: Toulouse'wer

Output: Toulouse’wer

I tried using the following 2 commands:

<xsl:variable name="apos" select='"&apos;"'/> <xsl:variable name="rsquo">&#39;</xsl:variable> translate(text(),$apos,$rsquo)

This command is still giving single quote(') as an output.

<xsl:variable name="apos" select='"&apos;"'/> <xsl:variable name="rsquo" select='"&rsquo;"'/>

Here, in this command I am not able to declare the second variable(rsquo) in xslt.

Please Advice.

Upvotes: 1

Views: 1949

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116959

You are defining $rsquo wrong. &#39; is the apostrophe (same as &apos;). The code for the right single quotation mark is &#8217;. So you end up replacing the original apostrophe with itself.

Try it this way:

<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="translate(text(), $apos, '&#8217;')"/>

Upvotes: 2

Related Questions