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

Re: Replacing all Occurences of a String

Subject: Re: Replacing all Occurences of a String
From: "cutlass" <cutlass@xxxxxxxxxxx>
Date: Thu, 30 Aug 2001 15:52:30 +0100
exslt str replace example
for the replace function there is a pure XSLT template

http://www.exslt.org/str/functions/replace/str.replace.template.xsl

which means u need nothing special with respect to parser ( just need to
import and add str: namespace ! ).

i've been using sablotron since .40 and i have no probs with the pure XSLT
templates ( and test all pure XSLT exslt templates with it ), though .65
finally solves some long standing issues !

u will find a lot of discussion on this particular template, as to whats
quicker etc in the archives for this list.

there are so many approaches to this problem, u have to ask yourself if u
are creating something for the short or long term, if its the short term i
would follow David C' s approach using translate(), if its something more
long term then investigate the methods employed with the stylesheets i've
been mentioning.

here is an example to illustrate one method, this of course can be
optimised.

date.xml
---------------------------------------
<january>
<txt xml:lang="en">january</txt>
<txt xml:lang="de">february</txt>
</january>
<february>
<txt xml:lang="en">januar</txt>
<txt xml:lang="de">februar</txt>
</february>
........

your xsl
---------------------------------------
then match using
set up a global language parameter ( that u may opt to feed in later )
<xsl:param name="lang" select="'en'"/>

now bring in your date data
<xsl:variable name="datedata" select="document('date.xml')"/>

then use the following to get what u want
<xsl: value-of select="$datedata//january[@xml:lang=$lang]"/>

doing it this way means u can supply different datedata ( maybe abbrevs
etc ).

good luck, jim fuller






----- Original Message -----
From: "Roger" <roger@xxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, August 30, 2001 3:26 PM
Subject: AW:  Replacing all Occurences of a String


> hi jim
> isn't there maybe a simpler way? and can I use the exslt functions with
> sablotron 0.60?
> best
> roger
>
>
> huh ?
>
> try out this template here;
>
> http://www.exslt.org/str/functions/replace/index.html
>
> though u will be passing params, but of course u could recurse calling
this
> named template etc...
>
> u could also use many of the date/time templates here, or at other places
> that make facilities for delivering in different languages.
>
> good luck, jim fuller
>
> ----- Original Message -----
> From: "Roger" <roger@xxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Thursday, August 30, 2001 2:31 PM
> Subject:  Replacing all Occurences of a String
>
>
> > Hi there
> > I want to replace the english months with the german months. It is
> possible
> > that the elements <sfzRelease/> and <sfzProdjahr/> have several months,
> like
> > this:
> >
> > <sfzRelease>January, February 2001</sfzRelease>
> >
> > I want at the end:
> >
> > <sfzRelease>Januar, Februar 2001</sfzRelease>
> >
> > I took Michael Kay's replace.xsl Stylesheet (Replacing all Occurences of
a
> > String). But I don't want to give it the parameters in the stylesheet
> > itself. I made a xsl:choose with the parameters, but that isn't
accepted.
> > Can anyone help me with this.
> > Thanx very much
> > Roger
> >
> >
> >
> >
> >
> >
> > <?xml version="1.0" encoding="iso-8859-1"?>
> > <xsl:stylesheet
> > version="1.O"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >
> >
> > <xsl:param name="replace"/>
> > <xsl:param name="by"/>
> >
> > <xsl:choose>
> > <xsl:when test="$replace='January'">
> > <xsl:param name="by" select="Januar"/>
> > </xsl:when>
> >    <xsl:when test="$replace='February'">
> > <xsl:param name="by" select="Februar"/>
> > </xsl:when>
> > <xsl:when test="$replace='March'">
> > <xsl:param name="by" select="März"/>
> > </xsl:when>
> > <xsl:when test="$replace='May'">
> > <xsl:param name="by" select="Mai"/>
> > </xsl:when>
> > <xsl:when test="$replace='June'">
> > <xsl:param name="by" select="Juni"/>
> > </xsl:when>
> > <xsl:when test="$replace='July'">
> > <xsl:param name="by" select="Juli"/>
> > </xsl:when>
> > <xsl:when test="$replace='October'">
> > <xsl:param name="by" select="Oktober"/>
> > </xsl:when>
> > <xsl:when test="$replace='December'">
> > <xsl:param name="by" select="Dezember"/>
> > </xsl:when>
> > </xsl:choose>
> >
> >
> > <xsl:template name="do-replace">
> > <xsl:param name="text"/>
> > <xsl:choose>
> > <xsl:when test="contains($text,$replace)">
> > <xsl:value-of select="substring-before($text, $replace)"/>
> > <xsl:value-of select="$by"/>
> > <xsl:call-template name="do-replace">
> > <xsl:with-param name="text"
> > select="substring-after($text, $replace)"/>
> > </xsl:call-template>
> > </xsl:when>
> > <xsl:otherwise>
> > <xsl:value-of select="$text"/>
> > </xsl:otherwise>
> > </xsl:choose>
> > </xsl:template>
> >
> > <xsl:template match="sfzRelease | sfzProdjahr">
> > <xsl:copy>
> > <xsl:copy-of select="@*"/>
> > <xsl:apply-templates/>
> > </xsl:copy>
> > </xsl:template>
> >
> > <xsl:template match="text()">
> > <xsl:call-template name="do-replace">
> > <xsl:with-param name="text" select="."/>
> > </xsl:call-template>
> > </xsl:template>
> >
> > </xsl:stylesheet>
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.