Copied to clipboard

Flag this post as spam?

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


  • Bruno 30 posts 50 karma points
    May 24, 2010 @ 13:00
    Bruno
    0

    How get only a few characters of a string in xslt?

    How get only a few characters of a string in xslt?

    Example, get only 10 characters of a title.

    Thnaks

  • dandrayne 1138 posts 2262 karma points
    May 24, 2010 @ 13:03
    dandrayne
    2

    Hi Bruno

    xslt substring, as seen at http://www.w3schools.com/xpath/xpath_functions.asp

    ----

    fn:substring(string,start,len)
    fn:substring(string,start) Returns the substring from the start position to the specified length. Index of the first character is 1. If length is omitted it returns the substring from the start position to the end

    Example: substring('Beatles',1,4)
    Result: 'Beat'

    Example: substring('Beatles',2)
    Result: 'eatles'

    ----

    Dan

  • Kim Andersen 1447 posts 2196 karma points MVP
    May 24, 2010 @ 13:05
    Kim Andersen
    2

    Hi Bruno

    You could try out the umbraco.library:TruncateString-function. E.g:

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

    The above code-snippet would give you the first 10 characters of the title-field on the current page, and in the end automatically insert three dots (...).

    You could try to play around with the function if it fits your needs.

    /Kim A

  • Bruno 30 posts 50 karma points
    May 24, 2010 @ 13:06
    Bruno
    0

    Thanks a lot Dan ;)

  • Bruno 30 posts 50 karma points
    May 24, 2010 @ 13:08
    Bruno
    0

    Thanks a lot to Kim A.

    I´m sure that your answer will help me. Thanks

  • Sam 184 posts 209 karma points
    Feb 26, 2011 @ 22:06
    Sam
    0

    Thanks Kim,

    This was just what I was after :)

    Sam.

  • Giorgos Grispos 145 posts 179 karma points
    Feb 26, 2011 @ 22:28
    Giorgos Grispos
    1

    Hello,

    If you really need to be the clever enough, use ucomponents and let the GetFirstWords xslt function to do the job

    ucomponents.strings:GetFirstWords(,,)

    that works better for short description

    Cheers, Giorgos

  • sun 403 posts 395 karma points
    Feb 27, 2011 @ 01:32
    sun
    0

    <xsl:value-of select="substring(string,startlocation,length)"/>

    no need to call any umbraco function

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2011 @ 11:53
    Fuji Kusaka
    0

    Hi Kim,

     

    I have tried this in my XSLT but nothing is showing up.

     <xsl:value-of select="umbraco.library:TruncateString($currentPage/data[@alias='eventTitle'],100,'...')" disable-output-escaping="yes"/>

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 04, 2011 @ 19:11
    Kim Andersen
    0

    Hi Fuji

    Which version of Umbraco are you using? If you are using one of the newer versions (4.5+) you're probably using the new XML shcema. Then you should do like this:

    <xsl:value-ofselect="umbraco.library:TruncateString($currentPage/eventTitle,100,'...')"disable-output-escaping="yes"/>

    If this doesn't work, could you make sure that the current page has a property with an alias of eventTitle, and that this field is not empty?

    Does it help?

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2011 @ 19:28
    Fuji Kusaka
    0

    Hi Kim,

    Yes am using new schema v4.7...and got it working like this instead

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

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2011 @ 19:29
    Fuji Kusaka
    0

    But thanks for replying and for the support

     

    //fuji

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 04, 2011 @ 20:05
    Kim Andersen
    0

    Ahh okay, so you're inside some kind of loop then right? Either a for-each or an apply-templates since you don't need the $currentPage.

    But cool that you got it sorted out Fuji :)

    /Kim A

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2011 @ 20:12
    Fuji Kusaka
    0

    You're right...the struture changed during the course of the project .....but in the end its working.

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft