using translate()

X

Xeon

Hi,

I'm trying to replace spaces with %20 with help of translate, but not
successfull. Here's a node in the xml file :

<title>This is some test title</title>

The xsl code I'm using :

<xsl:value-of select="translate(title, ' ', '%20')"/>

<xsl:variable name="uri_spacer">%20</xsl:variable>
<xsl:value-of select="translate(title, ' ', $uri_spacer)"/>

Both code yields to this result :
This%is%some%test%title

The target result :
This%20is%20some%20test%20title

Could somebody tell me how can I achieve this?

TIA
 
D

Dimitre Novatchev

Using FXSL one writes:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:testmap="testmap"
exclude-result-prefixes="xsl testmap"<xsl:import href="str-map.xsl"/>

<!-- to be applied on any xml source -->

<testmap:testmap/>

<xsl:eek:utput omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<xsl:variable name="vTestMap" select="document('')/*/testmap:*[1]"/>
<xsl:call-template name="str-map">
<xsl:with-param name="pFun" select="$vTestMap"/>
<xsl:with-param name="pStr" select="'This is some test'"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="double" match="*[namespace-uri() = 'testmap']">
<xsl:param name="arg1"/>
<xsl:choose>
<xsl:when test="$arg1 = ' '">%20</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="$arg1"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>


The result is:

This%20is%20some%20test




=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top