URL string manipulation

Discussion in 'XML' started by adam bob, Sep 25, 2007.

  1. adam bob

    adam bob Guest

    Hello, I'm struggling with an image mechanism I'm trying to build
    which basically manipulates a URL string.

    This is the sort URL that is gained from an InfoPath form

    https://xxx-xxx.xxx.xxx.com/content/00000xxx/xxx/xxx.jpg

    However I need to manipulate it so it also displays like this;

    https://xxx-xxx.xxx.xxx.com/content/00000xxx/xxx/_t/xxx_JPG.jpg

    As you can see it adds an '_t' and a '_JPG' into the URL string.

    This is where I am up to now, which from what I can see adds a '_' in
    front of the URL.

    ______________________________________________________________________________________

    <xsl:eek:utput method="html"/>
    <xsl:template match="/">
    <xsl:variable name="url" select="my:myFields/my:URL"/>
    <xsl:call-template name="truncate">
    <xsl:with-param name="string" select="$url"/>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="truncate">
    <xsl:param name="string"/>
    <xsl:param name="counter" select="3"/>
    <xsl:if test="$string!='' and $counter!=0">
    <xsl:text>_</xsl:text>
    <xsl:choose>
    <xsl:when test="contains($string, ' ')">
    <xsl:value-of select="substring-before($string, '/')"/>
    <xsl:call-template name="truncate">
    <xsl:with-param name="string" select="substring-
    after($string, '/')"/>
    <xsl:with-param name="counter" select="$counter - 1"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="$string"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:if>
    </xsl:template>

    __________________________________________________________________________________________

    Please advise or show me some useful code.

    Many thanks in advance
    adam bob, Sep 25, 2007
    #1
    1. Advertising

  2. If you need to do more complicated string manipulation that may involve
    iterating through the string or doing things the basic functions can't
    easily handle, check out the relevant sections of the XSLT FAQ. In
    particular, see the techniques described in

    http://www.dpawson.co.uk/xsl/sect2/StringReplace.html
    and
    http://www.dpawson.co.uk/xsl/sect2/N7240.html

    (Note that this complexity is necessary only because you want to replace
    "the last instance of /", and the basic XPath operations don't appear to
    include a last-position-of function.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Sep 25, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon paugh
    Replies:
    1
    Views:
    687
  2. Aaron

    URL Manipulation

    Aaron, Aug 7, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    1,928
    =?Utf-8?B?SmFrb2IgQ2hyaXN0ZW5zZW4=?=
    Aug 8, 2005
  3. Just D.
    Replies:
    0
    Views:
    406
    Just D.
    Aug 11, 2004
  4. jason
    Replies:
    7
    Views:
    107
    jason
    Jul 23, 2003
  5. nick
    Replies:
    1
    Views:
    442
    David Mark
    Feb 13, 2011
Loading...

Share This Page