[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Replacing all Occurences of a String
"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"?> <replacements> <replacement> <from>January</from> <to>Januar</to> </replacement> <replacement> <from>February</from> <to>Februar</to> </replacement> <!-- and so on --> </replacements> 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: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="process"> <xsl:with-param name="text" select="."/> <xsl:with-param name="replacements" select="document('replacements.xml')/replacements/replacement"/> </xsl:call-template> </xsl:template> <xsl:template name="process"> <xsl:with-param name="text"/> <xsl:with-param name="replacements"/> <xsl:choose> <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:call-template> </xsl:with-param> <xsl:with-param name="replacements" select="$replacements[position() > 1]"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Untested. HTH anyway. Try an extension for multi-language supprot by yourself. J.Pietschmann XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|