Copied to clipboard

Flag this post as spam?

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


  • Al Gilson 7 posts 27 karma points
    Sep 03, 2010 @ 15:57
    Al Gilson
    0

    What's more efficient?

    We're running Umbraco 4.5.2 on .NET 3.5, and have a question re: efficiency. Set up: i have a phone number in a session variable that I'd like to display without any formatting. For example:

    <xsl:value-of select="umbraco.library:Session('strTollFree')"  />

    strTollFree could = 1 (888) 555-1212, but what I'd like to display is 18885551212.

    I figure I could do it with a C# replace as described here:

    http://our.umbraco.org/wiki/reference/xslt/extend-your-xslt-with-custom-functions

    or, I could use an XSLT custom replace such as:

    http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx

    Which is more efficient? This XSLT output could be displayed on every page of our site, so it's going to be run fairly often.

    Thanks,

    - Al

     


     

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Sep 03, 2010 @ 16:10
    Thomas Höhler
    3

    What about storing the phone number formatted as you want in a second session variable?

    Just my two cents ;-)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 03, 2010 @ 16:17
    Dirk De Grave
    0

    Agree with Thomas, just store the non formatted phone number in the session, and retrieve it from xslt in whatever page, no need for extra calls.

     

    Cheers,

    /Dirk

  • Al Gilson 7 posts 27 karma points
    Sep 03, 2010 @ 16:20
    Al Gilson
    0

    Funny, right in front of me and didn't see it. Thanks guys!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 03, 2010 @ 18:52
    Chriztian Steinmeier
    2

    Hi Al,

    Just in case you decide to keep the formatting (for whatever reason) there's a nifty built-in function you can use for exactly this purpose - it's called translate() and it does a tricky little business of replacing characters in strings. You can google it to get the nitty gritty on it, but for your example you'd do this:

    <xsl:variable name="number" select="umbraco.library:Session('strTollFree')" />
    
    <xsl:value-of select="translate($number, ' ()-+', '')" />
    
    

    /Chriztian

  • Al Gilson 7 posts 27 karma points
    Sep 03, 2010 @ 21:09
    Al Gilson
    0

    That translate function will come in handy down the road. Much appreciated.

    - Al

     

Please Sign in or register to post replies

Write your reply to:

Draft