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

    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)


  • Chriztian Steinmeier 2774 posts 8653 karma points MVP 6x admin c-trib
    Sep 24, 2013 @ 21:22
    Chriztian Steinmeier

    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)" />


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

    Thanks again Chriztian, That works perfectly!


Please Sign in or register to post replies

Write your reply to: