Copied to clipboard

Flag this post as spam?

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


  • rich hamilton 117 posts 136 karma points
    Feb 29, 2012 @ 19:16
    rich hamilton
    0

    Remove line breaks for locator package

    I have installed the locator package and after some messing managed to get it to work.

    I want to use the bodyText in the infoWindow popup.

    e.g.:

    var myHtml = "<h2><xsl:value-of select="@nodeName"/></h2>";

    myHtml += "<xsl:value-of select="bodyText"/>";

     

    But, the bodyText has line breaks in the string, so it breaks the javascript and the map will not show.

     

    Any suggestions how I can easily strip out the unwanted line breaks?


    Thanks


  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 29, 2012 @ 19:55
    Chriztian Steinmeier
    1

    Hi Rich,

    You can use the normalize-space() function for that, e.g.:

    myHtml +='<xsl:value-of select="normalize-space(bodyText)" />';

    This will convert all consecutive runs of whitespace characters (spaces, tabs, newlines etc.) into a single space.

    If you want to escape the newlines for use in the JavaScript, you can use the Replace extension function:

    myHtml +='<xsl:value-of select="umbraco.library:Replace('&#x0A;', '\n')" />';

    /Chriztian

  • rich hamilton 117 posts 136 karma points
    Mar 01, 2012 @ 10:47
    rich hamilton
    0

    Thanks, that is great. I used the first one and it worked (but crashes if there are any single quotes anywhere in the bodyText).

    I am not sure how the second line would work, how does it reference the bodyText?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 01, 2012 @ 11:30
    Chriztian Steinmeier
    1

    Hi Rich,

    Ha - yeah, that's a mystery - sorry 'bout that :-)

    Here's how to it's supposed to look:

    <xsl:value-of select="umbraco.library:Replace(normalize-space(bodyText), '&#x0A;', '\n')" />

    - but you'll have the same problems with quote characters - you'll need to escape the ones that are the same as the one you use around the string (\" for double-quotes or \' for single-quotes).

    /Chriztian

  • rich hamilton 117 posts 136 karma points
    Mar 01, 2012 @ 11:42
    rich hamilton
    0

    so in the Replace, I could do

    <xsl:value-ofselect="umbraco.library:Replace(normalize-space(bodyText), "&#39;", "\'")"/>
  • rich hamilton 117 posts 136 karma points
    Mar 01, 2012 @ 11:48
    rich hamilton
    0

    that didn't work due to the mix of single/ double quotes.

    the \' breaks it.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 01, 2012 @ 11:56
    Chriztian Steinmeier
    2

    Hi Rich,

    This is because the &#39; will be interpreted as an actual single quote and thus, breaks the code...

    You should be able to circumvent it like this:

    <xsl:variable name="apos">'</xsl:variable>
    <xsl:variable name="escaped-apos">\'</xsl:variable>
    
    <xsl:value-of select="umbraco.library:Replace(normalize-space(bodyText), $apos, $escaped-apos)" />

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft