Copied to clipboard

Flag this post as spam?

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


  • Rich Green 2246 posts 4008 karma points
    May 19, 2010 @ 15:53
    Rich Green
    0

    Removing TinyMCE line breaks

    Can't get this to work at all

    I need to strip out all the line breaks so I can use the tinymce value in javascript.

    I've tried:

    <xsl:variable name="Address" select="umbraco.library:ReplaceLineBreaks($currentPage/data [@alias = 'contactAddress'])"/>
    
    
    <xsl:variable name="cleanAddress" select="umbraco.library:Replace($Address, '\r', '')"/>
    <xsl:variable name="cleanAddress select="umbraco.library:Replace($Address, '\n', '')"/>
    <xsl:variable name="cleanAddress" select="umbraco.library:Replace($Address, '\n\r', '')"/>
    <xsl:variable name="cleanAddress" select="umbraco.library:ReplaceLineBreaks($Address)"/>

    The value of address is 

    <p>Address 1<br/>
    Address 2<br/>
    Address 3<br/>
    Postcode<p>
    

    But I need it to be 

    <p>Address 1<br/>Address 2<br/>Address 3<br/>Postcode<p>

     

    Any ideas?

    Cheers, 

    Rich

     

     

  • Jeff Grine 149 posts 189 karma points
    May 19, 2010 @ 16:07
    Jeff Grine
    0

    Doesn't look like umbraco.library has what you need, so you're probably going to need to write your own xslt extension to replace line breaks using RegEx.Replace. Pretty straightforward and a useful thing to have set up when you need other functions like this.

    http://en.wikibooks.org/wiki/Umbraco/Create_xslt_exstension_like_umbraco.Library_in_C

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    May 19, 2010 @ 16:16
    Douglas Robar
    1

    You'll either need to use some of the exslt extension methods (such as regex, but there may be others in there) or build your own extension (or use incline c#).

    Or... and this would be quick and sneaky if it works...

    <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>

    Notice the indent="no" element. Give that a shot and see what happens first.

    cheers,
    doug.

     

     

  • dandrayne 1138 posts 2262 karma points
    May 19, 2010 @ 16:52
    dandrayne
    0

    Did you also try 

    <xsl:variable name="cleanAddress" select="umbraco.library:Replace($Address, '&#xA;', '')"/>

    Dan

  • Rich Green 2246 posts 4008 karma points
    May 20, 2010 @ 10:24
    Rich Green
    0

    Thanks guys, I went with a quick C# solution in the end.

    Didn't get to try another solution but will try then when I get a sec and report back.

     

    Thanks again.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 20, 2010 @ 10:49
    Jan Skovgaard
    4

    Hi Rich

    Glad you found a solution. But I actually think that you can maybe use the XSLT function normalize-space() to solve this. I had an issue a few days ago where I needed to fetch some rich text data from umbraco inside a javascript. The script kept choking when it received the data because of line breaks in the HTML.

    I solved it using the above mentioned function. So you could try writing this:

    <xsl:variable name="Address" select="normalize-space(umbraco.library:ReplaceLineBreaks($currentPage/data [@alias = 'contactAddress']))"/>
    <xsl:value-of select="$Address" />

    So if the stuff you are doing now does not work then try it out :-)

    /Jan

  • Paul Blair 466 posts 731 karma points
    Jun 14, 2010 @ 06:15
    Paul Blair
    0

    Jan,

    Your solution worked well for me - I was taking data from the rich text editor so did not need the ReplaceLineBreaks call.

    Thanks

    Paul

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies