Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 343 karma points
    Jul 08, 2015 @ 10:04
    Tom Cowling
    0

    xslt render html

    Hey,

    Apologies if this has been answered before. I want to display the first 300 characters of a rich text editor and have done the following (which works fine).

    <xsl:value-of select="umbraco.library:TruncateString(contents,300,'...')" disable-output-escaping="yes" />
    

    What I would like to do after this is to strip out all images, styling and links. Is there any way I can grab all the outputted text and the strip out all code so it's just plain text?

    The reason I put the disable-output-escaping on in the first place is so I don't get any of the html code being pulled in, but it throws in pictures and links and looks unsightly.

    Any help would be much appreciated!

    Thanks,

    Tom

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 08, 2015 @ 10:10
    Chriztian Steinmeier
    100

    Hi Tom,

    There is also a StripHtml() extension that you could try to combine with TruncateString() (do the stripping first).

    (And then remove the disable-output-escaping attribute again)

    Hope that helps,

    /Chriztian

  • Tom Cowling 144 posts 343 karma points
    Jul 08, 2015 @ 10:18
    Tom Cowling
    0

    Perfect - exactly what I was looking for.

    Updated code for anyone who may need it in the future (not sure if you can combine the two for a neater solution, but this was the method I used):

        <xsl:variable name="introtext" select="umbraco.library:StripHtml(contents)" />
        <xsl:value-of select="umbraco.library:TruncateString($introtext,300,'...')" />
    

    Thanks as always for the quick response Chriztian!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jul 08, 2015 @ 10:21
    Chriztian Steinmeier
    0

    No worries, Tom :-)

    You can combine into a single line, but there's no penalty for creating a variable first - only improves the readability of the second line, IMO.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft