Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bruno Alexandre 29 posts 38 karma points
    Jul 12, 2011 @ 11:29
    Bruno Alexandre
    0

    How to escape single quotes on converting Richtext Editor into JSON Data

    from Chriztian Steinmeier answer the \n are normalized into 


    so I would replace like this:

     

    <xsl:value-of select="Exslt.ExsltStrings:replace($varDescription, '&#10;', '&lt;br/&gt;')" />

     

    How would I conver a single quote into \'

    so my JSON Data would not be broken?

    my current JSON Description (that's a Richtext control) XSLT is:


    <xsl:variable name="varDescription" select="normalize-space(htmlContent)"/>

    description: '<xsl:value-of select="$varDescription" disable-output-escaping="yes" />'

     

    and I wanted to have something like:

    <xsl:value-of select="Exslt.ExsltStrings:replace($varDescription, '\'', '\\\'')" 
                  disable-output-escaping="yes" />

    but I get a syntax error...

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 12, 2011 @ 11:35
    Jan Skovgaard
    0

    Hi Bruno

    If I remember correctly you get a syntax error because you're trying to use the apostrophe in some of the content you're trying to replace. What happens if you try to replace &#39; instead of ' ? (this should be the entity number for the apostrophe).

    <xsl:value-of select="Exslt.ExsltStrings:replace($varDescription, '&#39;', '\\&#39;')" disable-output-escaping="yes" />

    Could this work or do I misunderstand what you're trying to do?

    /Jan

  • Bruno Alexandre 29 posts 38 karma points
    Jul 12, 2011 @ 11:38
    Bruno Alexandre
    0

    Hej Jan,

    I did try but I get syntax error :-/

     

    http://www.balexandre.com/temp/2011-07-12_1137.png

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 12, 2011 @ 11:44
    Kim Andersen
    2

    Hi Bruno

    Could you try this snippet:

    <xsl:variable name="string1"><![CDATA[']]></xsl:variable>
    <xsl:variable name="string2"><![CDATA[\']]></xsl:variable>
    <xsl:value-of select="umbraco.library:Replace(normalize-space($varDescription), $string1, $string2)" disable-output-escaping="yes" />

    I'm pretty sure this will replace the ' with a \'

    /Kim A

  • Bruno Alexandre 29 posts 38 karma points
    Jul 12, 2011 @ 11:49
    Bruno Alexandre
    0

    Hej Kim,

     

    works like a charm, thought I prefered to convert to &#8217; (open single quote)

    Exslt.ExsltStrings:replace($varDescription, $string1, '&#8217;')

     

    Thank you.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 12, 2011 @ 11:52
    Kim Andersen
    0

    Cool. Yeah, you could do that as well - that's up to you :)

    I know it's maybe not the most beautiful code to do it this way, but in some cases you just need to do what it takes to make it work right ;)

    /Kim A

  • Bruno Alexandre 29 posts 38 karma points
    Jul 12, 2011 @ 11:55
    Bruno Alexandre
    0

    yeah, as long as it works :)

     

    I'm missing some JSON converters from Umbraco.library, as JSON is now the ultimate data transfer type.

    Would be a great adition.

    :o)

     

Please Sign in or register to post replies

Write your reply to:

Draft