Posted By

iroybot on 05/26/10


Tagged

php quote XSL single apos singlequote pre-parsed


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

iroybot
Tyster


Replace single quotes


 / Published in: XSLT
 

replacing single quotes with its (double-escaped) entity, for use of a text within xsl.

  1. <xsl:template match="text">
  2. <xsl:variable name="apos">'</xsl:variable>
  3. <xsl:variable name="cleaned">
  4. <xsl:call-template name="_replace_string">
  5. <xsl:with-param name="string" select="." />
  6. <xsl:with-param name="find" select="$apos" />
  7. <xsl:with-param name="replace" select="'&amp;apos;'" />
  8. </xsl:call-template>
  9. </xsl:variable>
  10. <xsl:value-of select="$cleaned" />
  11. </xsl:template>
  12.  
  13. <xsl:template name="_replace_string">
  14. <xsl:param name="string" select="''"/>
  15. <xsl:param name="find" select="''"/>
  16. <xsl:param name="replace" select="''"/>
  17. <xsl:choose>
  18. <xsl:when test="contains($string,$find)">
  19. <xsl:value-of select="concat(substring-before($string,$find),$replace)"/>
  20. <xsl:call-template name="_replace_string">
  21. <xsl:with-param name="string" select="substring-after($string,$find)"/>
  22. <xsl:with-param name="find" select="$find"/>
  23. <xsl:with-param name="replace" select="$replace"/>
  24. </xsl:call-template>
  25. </xsl:when>
  26. <xsl:otherwise>
  27. <xsl:value-of select="$string"/>
  28. </xsl:otherwise>
  29. </xsl:choose>
  30. </xsl:template>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: iroybot on January 25, 2011

this is needed in order to parse xml data with php $var = ']]>

You need to login to post a comment.