Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    Feb 10, 2010 @ 12:28
    Darryl Godden
    0

    Substring in XSLT

    Another day, another question...

    I've looked at various references and I believe this should work, but it does not:

    <xsl:value-of select='substring(data [@alias = "EventDescription"],1,20)' disable-output-escaping="yes" />

    I'm trying to shorten the field for display as it is rather lengthy. Can you help?

    TIA.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 10, 2010 @ 12:37
    Dirk De Grave
    2

    Hi Darryl,

    Have you tried switching quotes/double quotes? If you're in a loop, it might also be best practice to include ./ before the data fragment, to make sure you're getting info from the current node in the loop

    <xsl:value-of select="substring(./data [@alias = 'EventDescription'],1,20)" disable-output-escaping="yes" />

     

    Cheers,

    /Dirk

  • Kim Andersen 1447 posts 2197 karma points MVP
    Feb 10, 2010 @ 12:52
    Kim Andersen
    4

    Otherwise you could also try out the extension: umbraco.library:TruncateString

    You can use it like this:

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

    This function cuts the string after 20 characters, and insert ... at the end of the line. It's actually pretty usefull. If the EventDescription-field is content from a text-editor it would be smart to combine it with another extension called stripHtml like this:

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

    This makes sure, that the truncateString doesn't break up a html-tag, like a link or so.

     

    /KIm A

  • Darryl Godden 145 posts 197 karma points
    Feb 10, 2010 @ 14:08
    Darryl Godden
    0

    That worked perfectly Kim, thank you!

    Sorry Dirk, I couldn't get yours to work...

  • Kim Andersen 1447 posts 2197 karma points MVP
    Feb 10, 2010 @ 16:01
    Kim Andersen
    0

    Any time Darryl...

    /Kim A

  • Luis Soto 2 posts 22 karma points
    Oct 31, 2013 @ 20:13
    Luis Soto
    0

    Hi Guys Im newbie in xslt how can i split a text I mean i have a string "Ticket # 123456 was placed on 12/10/2013" i need only 123456

     

    Thanks

     

  • Luis Soto 2 posts 22 karma points
    Oct 31, 2013 @ 20:17
    Luis Soto
    0

     

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 31, 2013 @ 22:10
    Chriztian Steinmeier
    0

    Hi Luis - welcome to the forum!

    You will likely get much better results if you post a new question instead of continuing in this thread, since this one is already marked as solved.

    /Chriztian

  • 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