xsl-list
[Top] [All Lists]

Re: Hmmmm.... translate function

2003-03-14 14:50:27

"Karl Stubsjoen" <karl(_at_)azprogolf(_dot_)com> wrote in message
news:003701c2ea62$55b89550$0afc020a(_at_)inside(_dot_)fender(_dot_)(_dot_)(_dot_)
Translate is on character basis, that is translating the character on
the 2nd string to the character on the same position on the 3rd string.
More characters you provide on 3rd string will just be ignored.
Seems there's no convinient function in xsl to be found to solve your
problem. You may want to combine substring-before and substring-after
functions.

Err... that stinks.

With FXSL one will use the "str-map" template like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:replPlus="f:replPlus"

   <xsl:import href="str-map.xsl"/>

   <xsl:output method="text"/>

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

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

   <xsl:template match="/">
     <xsl:variable name="vTestMap" select="document('')/*/replPlus:*[1]"/>
     <xsl:call-template name="str-map">
       <xsl:with-param name="pFun" select="$vTestMap"/>
       <xsl:with-param name="pStr" select="'X + Y + Z'"/>
     </xsl:call-template>
   </xsl:template>

    <replPlus:replPlus/>
    <xsl:template name="replPlus" match="replPlus:*">
      <xsl:param name="arg1"/>

      <xsl:choose>
        <xsl:when test="$arg1 = '+'">
          <xsl:value-of select="'%2B'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$arg1"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

The result of applying this transformation on any xml.source (ignored) is to
translate the "+" in "X + Y + Z" into "%2B":

X %2B Y %2B Z



=====
Cheers,

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




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>