URL string manipulation

A

adam bob

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
 
J

Joseph Kesselman

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top