/ Published in: XSLT
replacing single quotes with its (double-escaped) entity, for use of a text within xsl.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<xsl:template match="text"> <xsl:variable name="apos">'</xsl:variable> <xsl:variable name="cleaned"> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="." /> <xsl:with-param name="find" select="$apos" /> <xsl:with-param name="replace" select="'&apos;'" /> </xsl:call-template> </xsl:variable> <xsl:value-of select="$cleaned" /> </xsl:template> <xsl:template name="_replace_string"> <xsl:param name="string" select="''"/> <xsl:param name="find" select="''"/> <xsl:param name="replace" select="''"/> <xsl:choose> <xsl:when test="contains($string,$find)"> <xsl:value-of select="concat(substring-before($string,$find),$replace)"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find)"/> <xsl:with-param name="find" select="$find"/> <xsl:with-param name="replace" select="$replace"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template>