[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Replacing substring with value during transform

Subject: [xsl] Replacing substring with value during transform
From: John English <john.foreign@xxxxxxxxx>
Date: Wed, 12 Sep 2012 19:17:40 +0300

I'm trying to internationalize a webapp which generates XML to be
transformed into HTML. I translate all the necessary servlet output,
but I sometimes have XML that translates into HTML with embedded
strings that need translating. For example, here's a fragment of
the template that generates a standard page header:

  <td align='center' valign='middle'>
    <xsl:value-of select='@date'/>
    <br />
    {#User#}: <xsl:value-of select='@user'/>
  <td align='right' valign='middle' width='30%'>
    <a class='boxed' href='logout'>{#Logout#}</a>

Strings enclosed in {#...#} are translated when the stylesheet is
first loaded. My problem is when embedding values into those strings.
In Java I can use MessageFormat to plug in values:

fmt.format(translate("Add a new {0}"), new String[]{ ""+n });

In the XML template I'm reduced to doing this:

{#Add a new#} <xsl:value-of select='@n'/>

which doesn't play well in languages where the adjective "new" needs to
follow the noun, for example. I'd like to be able to do something along
the following lines in my stylesheet:

format('{#Add a new {0}#}',<xsl:value-of select='@n'/>)

Can anyone suggest how I could implement something like this?

John English

Current Thread