using translate()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xeon

    #1

    using translate()

    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="transla te(title, ' ', '%20')"/>

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

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

    The target result :
    This%20is%20som e%20test%20titl e

    Could somebody tell me how can I achieve this?

    TIA
  • Dimitre Novatchev

    #2
    Re: using translate()

    Using FXSL one writes:


    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:testmap=" testmap"
    exclude-result-prefixes="xsl testmap"[color=blue]
    >[/color]
    <xsl:import href="str-map.xsl"/>

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

    <testmap:testma p/>

    <xsl:output omit-xml-declaration="ye s" indent="yes"/>

    <xsl:template match="/">
    <xsl:variable name="vTestMap" select="documen t('')/*/testmap:*[1]"/>
    <xsl:call-template name="str-map">
    <xsl:with-param name="pFun" select="$vTestM ap"/>
    <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:otherwis e>
    <xsl:copy-of select="$arg1"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    </xsl:stylesheet>


    The result is:

    This%20is%20som e%20test




    =====
    Cheers,

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



    "Xeon" <xdblade@zworg. com> wrote in message
    news:78321f06.0 307011445.707b3 8cc@posting.goo gle.com...[color=blue]
    > 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="transla te(title, ' ', '%20')"/>
    >
    > <xsl:variable name="uri_space r">%20</xsl:variable>
    > <xsl:value-of select="transla te(title, ' ', $uri_spacer)"/>
    >
    > Both code yields to this result :
    > This%is%some%te st%title
    >
    > The target result :
    > This%20is%20som e%20test%20titl e
    >
    > Could somebody tell me how can I achieve this?
    >
    > TIA[/color]


    Comment

    Working...