Copied to clipboard

Flag this post as spam?

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


  • Roger 195 posts 474 karma points
    Sep 24, 2013 @ 19:21
    Roger
    0

    Trim value of page item in XSLT

    is it possible to trim a page item in XSLT?

    for example, i want 3 chars trimmed from the right of a string or up to and including a comma in the string (this will always be 3 chars including the comma though)

    Thanks!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 24, 2013 @ 21:22
    Chriztian Steinmeier
    100

    Hi Roger,

    You can get the length of a string with the string-length() function - and you have three ways of grabbing parts of a string, by way of the substring(), substring-before() and substring-after() functions, so here's how to attack the "trim last 3 chars" scenario:

    <xsl:variable name="demoString" select="'1234,67'" />
    
    <!-- Grab the the substring from #1 to #(length - 3) -->
    <xsl:variable name="trimmed" select="substring($demoString, 1, string-length($demoString) - 3)" />
    

    /Chriztian

  • Roger 195 posts 474 karma points
    Sep 24, 2013 @ 21:42
    Roger
    0

    Thanks again Chriztian, That works perfectly!

    Roger

Please Sign in or register to post replies

Write your reply to:

Draft