Connecting Tech Pros Worldwide Forums | Help | Site Map

Replacing multiple spaces after word in field

Newbie
 
Join Date: Sep 2007
Posts: 27
#1: Sep 22 '07
Hi Guys

I hope this is a simple one for you.

I am basically displaying data onto my xml page using the following line of code:

<xsl:value-of select="carmanufacturer" />

An example of the resulting output would be, "Ford"

However, the "carmanufacturer" field in my table sometimes contains 2 words, for example, "Land Rover". Thus, the resulting output is, "Land Rover".

The output on my page is also hyperlinked and so the code is as follows:

<a class="type1" href="http://www.mywebsite.co.uk/{carmanufacturer}.asp"><xsl:value-of select="carmanufacturer" /></a>

The need the hyperlink url I would like to replace the spaces between the 2 words with a "-". Thus my link would point to:

http://www.mywebsite.co.uk/Land-Rover.asp

So I used."{translate(carmanufacturer,' ','-')}" to achieve this. Thus,

<a class="type1" href="http://www.mywebsite.co.uk/{translate(carmanufacturer,' ','-')}.asp"><xsl:value-of select="carmanufacturer" /></a>

However, the problem I have now is that some of the data within my field contains many spaces after the final word. For example

"land rover "

How would it get this data to appear in my hyperlink without the spaces at the end of the last word, so it displays as:

http://www.mywebsite.co.uk/Land-Rover.asp and not http://www.mywebsite.co.uk/Land-Rover .asp

PS: Unfortunately, I do not have access to my database and therefore unable to change the format of the table/fields etc. Thus, I have to make this work at script level.

Any help would be fully appreciated.

Rod from the UK

Newbie
 
Join Date: Sep 2007
Posts: 27
#2: Sep 22 '07

re: Replacing multiple spaces after word in field


Hi guys

In relation to my query in the first thread, I have tried the following line of code but it still doesn't work:

"{translate(trim(carmanufacturer,' ','-')}"

I get the following error:

---------------error--------------------
msxml3.dll error '80004005'

'trim' is not a valid XSLT or XPath function
---------------end---------------------

I think this is something to do with the fact that I have version XSLT 1.0 installed and not version 1.0, but I could be wrong?

Any help would be fully apprecaited.

Best regards

Rod Joseph
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Sep 24 '07

re: Replacing multiple spaces after word in field


normalize-space()

as posted in other forum.
take a look at www.w3schools.com, particularly the xpath functions section.
Reply