Copied to clipboard

Flag this post as spam?

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


  • sdfsfm 70 posts 94 karma points
    Jul 28, 2010 @ 14:28
    sdfsfm
    0

    Displaying first 100 characters in a description

    I'm trying to get the first 100 characters from  a product description[richtextbox name productDesc] I'm using

        <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./data[@alias = 'productDesc']), 100,'...')"/>

    Which i got from another post here on the forum, but it doesn't seem to be working for me.Sorry I've just start working with xslt and still trying to learn the ins and outs of it.

  • Dimitris Tsoukakis 33 posts 59 karma points
    Jul 28, 2010 @ 14:45
    Dimitris Tsoukakis
    0

    Try this

    <xsl:value-of select="concat(substring(umbraco.library:StripHtml(./data[@alias = 'productDesc']),1,100),'...')" />

    I think you should also use disable-output-escaping="yes"

  • sdfsfm 70 posts 94 karma points
    Jul 28, 2010 @ 14:51
    sdfsfm
    0

    Thanks Dimitris, but that seems to output only the '...'

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 28, 2010 @ 14:56
    Matt Brailsford
    1

    Hi Ivor,

    Are you using Umbraco 4.5 by any chance? If so you'll probably want to change it to:

    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(./productDesc), 100,'...')"/>

    Matt

  • sdfsfm 70 posts 94 karma points
    Jul 28, 2010 @ 15:16
    sdfsfm
    0

    Hi Mat,

    Thanks! that worked.

  • Eddie Foreman 215 posts 288 karma points
    Sep 28, 2010 @ 18:22
    Eddie Foreman
    0

    Hi Matt

    Is it possible to expanded your solution, with a delimiter.  I.e. a full stop.  I would like to grab x number of characters.  If the last character is not a full stop, go back down the string and cut of at the first full stop.  Done, a similiar thing in a usercontrol, but wondered if it was possible in an xslt.

    Thanks again

    Eddie

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 28, 2010 @ 18:50
    Matt Brailsford
    0

    Hi Eddie,

    It's not possible with the built in library methods, but you could definatley create an XSLT extension library of your own and create a method to what you are looking for. If you have a method, it might be worth getting in touch with the uComponents guys as they have some handy extension methods, so could be handy to add it.

    Matt

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 28, 2010 @ 21:27
    Lee Kelleher
    0

    Hi Eddie,

    As Matt mentions, we've got all sorts of string-based functions in uComponents XSLT extensions; including one called "GetFirstWords", which will truncate the string after so many words, take a look:

    http://ucomponents.codeplex.com/SourceControl/changeset/view/67046#1411983

    If you do have any killer code snippets that you'd like to see in uComponents, please let us know!

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft