2008-01-23

How to escape single quotes in XSLT

...well, as much as I have figured out, there is no clean built-in solution for escaping single quotes (') in XSLT. You need this if you e.g. want to generate JavaScript function calls within the generated XML file. So I have found a workaround resp. a not really nice hack to solve this problem as you can see in the following:


<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="concat('javaScript_Function_With_String_Parameter (',$apos,.,$apos,')')"/>


In this way you can generate the JavaScript function call "javaScript_Function_With_String_Parameter('currentValue')".

4 comments:

  1. Anonymous23.3.09

    Helped me a lot.
    Thanx!

    ReplyDelete
  2. Thanks man, this is realy rare solution! And most importent IT WORKS! :)

    ReplyDelete
  3. Great solution, thanks

    ReplyDelete