469,356 Members | 2,250 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

URL string manipulation

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/...xx/xxx/xxx.jpg

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

https://xxx-xxx.xxx.xxx.com/content/..._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:output 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:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

__________________________________________________ ________________________________________

Please advise or show me some useful code.

Many thanks in advance

Sep 25 '07 #1
1 2775
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
Sep 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

32 posts views Thread by tshad | last post: by
29 posts views Thread by zoro | last post: by
4 posts views Thread by WaterWalk | last post: by
10 posts views Thread by micklee74 | last post: by
3 posts views Thread by crprajan | last post: by
3 posts views Thread by frankeljw | last post: by
22 posts views Thread by mann_mathann | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.