[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: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Thu, 30 Aug 2001 18:43:24 +0200
javascript replace all occurences
"Roger" <roger@xxxxxxxx> wrote:
> 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.

I hope i have understood correctly that you don't want to hardwire
the replacement pairs in the style sheet.
You can build a XML file which holds the pairs and pull it into
the style sheet via document(). Iterating over the replacements
ist awkward, unfortunately.

File replacements.xml
  <?xml version="1.0" encoding="iso-8859-1"?>
    <!-- and so on -->

Simplified style sheet:
  <?xml version="1.0" encoding="iso-8859-1"?>
  <xsl:stylesheet version="1.O" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template name="do-replace">
     <xsl:param name="text"/>
     <xsl:param name="replace"/>
     <xsl:param name="by"/>
       <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:value-of select="$text"/>

   <xsl:template match="sfzRelease | sfzProdjahr">
       <xsl:copy-of select="@*"/>

   <xsl:template match="text()">
     <xsl:call-template name="process">
       <xsl:with-param name="text" select="."/>
       <xsl:with-param name="replacements"

   <xsl:template name="process">  
     <xsl:with-param name="text"/>
     <xsl:with-param name="replacements"/>
       <xsl:when test="replacements">
         <xsl:call-template name="process">
            <xsl:with-param name="text">
              <xsl:call-template name="do-replace">
                <xsl:with-param name="text" select="$text"/>
                <xsl:with-param name="replace" select="$replacements[1]/from"/>
                <xsl:with-param name="by" select="$replacements[1]/to"/>
          <xsl:with-param name="replacements" select="$replacements[position() &gt; 1]"/>
         <xsl:value-of select="$text"/>

Untested. HTH anyway.
Try an extension for multi-language supprot by yourself.


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

Current Thread


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.
First Name
Last Name
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.