[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Hmmmm.... translate function

Subject: Re: Hmmmm.... translate function
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 14 Mar 2003 22:50:27 +0100
translate function in xsl
"Karl Stubsjoen" <karl@xxxxxxxxxxxxx> wrote in message
news:003701c2ea62$55b89550$0afc020a@xxxxxxxxxxxxxxxx
> > 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.