This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Replacing all Occurences of a String
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Replacing all Occurences of a String
- From: "Tim Watts" <timw at 3d3 dot com>
- Date: Fri, 31 Aug 2001 10:13:26 +1000
- Reply-To: xsl-list at lists dot mulberrytech dot com
To add to Chris Bayes suggestion, here is another localization solution
If the stylesheet is only going to be using one language, rather than
loading a page with all the languages, you can choose to load the language
the page is going to be displayed in.
I use XML simular to:
english.xml
<words>
<jan>January</jan>
<feb>February</feb >
</words>
german.xml
<words>
<jan>Januar</jan>
<feb>Februar</feb>
</words>
french.xml
<words>
<jan>Janvier</jan>
<feb>...</feb>
</words>
By doing this I use document() and set a global variable by calling it like
so:
<xsl:variable name="language" select="document(german.xml'))/words" />
An XSL which can use this is shown below
XSL
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="language" select="document(german.xml'))/words" />
<xsl:template match="/">
<translated-phrases>
German Months
<translation>
<xsl:value-of select="$language/jan" />
</translation>
<translation>
<xsl:value-of select="$language/feb" />
</translation>
</translated-phrases>
</xsl:template>
</xsl:stylesheet>
Cheers,
Tim Watts
> -----Original Message-----
> From: Chris Bayes
>
> Have a look at
> http://www.biglist.com/lists/xsl-list/archives/200008/msg01300.html
> for some ideas on internationalization.
> You can extend this idea to handle
> your month conversions if your datafile looked like
> <dictionary>
> <months lang="en">
> <month abbr="jan">january</month>
> ...
> <month abbr="dec">december</month>
> </months>
> <months lang="fr">
> <month abbr="jan">janvier</month>
> ...
>
> Then to convert $monthtotrans from french to english abbreviation
> something like
> <xsl:value-of
> select="document('months.xml')/dictionary/months[@lang='en']/m
> onth[posit
> ion()/document('months.xml')/dictionary/months[@lang='fr']/mon
> th[@abbr=$
> monthtotrans]/@abbr
> Or
> <xsl:variable name="monthnum"
> select="count(preceding-sibling::*/document('months.xml')/dict
> ionary/mon
> ths[@lang='fr']/month[@abbr=$monthtotrans])" />
> <xsl:value-of
> select="document('months.xml')/dictionary/months[@lang='en']/m
> onth[$mont
> hnum]/@abbr" />
>
> Ciao Chris
>
>
> > -----Original Message-----
> > From: Roger
> >
> > The problem is I have all months and also all languages, like:
> >
> > <sfzSprache>Italian/German/Swiss-German/French</sfzLanguage>
> >
> > and I want in the end:
> >
> > <sfzSprache>Italienisch/Deutsch/Schweizerdeutsch/Französisch</
> > sfzLanguage>
> >
> >
> > If I only would have "German" or "October" it would be easy.
> > I would then transform it like this:
> >
> > <xsl:choose>
> > <xsl:when test="string-length(sfzSprache)>0">
> > Sprache:
> > <xsl:choose>
> > <xsl:when test="string(sfzSprache)='German'">
> > Deutsch <br />
> > </xsl:when>
> > <xsl:when test="string(sfzSprache)='French'">
> > Französisch <br />
> > </xsl:when>
> > <xsl:when test="string(sfzSprache)='English'">
> > Englisch<br />
> > </xsl:when>
> > <xsl:otherwise>
> > <xsl:value-of select="sfzSprache"/><br />
> > </xsl:otherwise>
> > </xsl:choose>
> >
> > roger
> >
> >
> > > > <sfzRelease>January, February 2001</sfzRelease>
> > > >
> > > > I want at the end:
> > > >
> > > > <sfzRelease>Januar, Februar 2001</sfzRelease>
> > >
> > > If you have a replace string template then probably the
> > > easiest thing to do is make a variable containg a node set of
> > > replacements eg
> > >
> > > <y en="January" de="Januar"/>
> > >
> > > then just make a recusive template that works down a list of
> > > y nodes, doing a replacement using the first y node then
> > > calling itself on the rest of the list.
> > >
> > > David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list