xsl-list
[Top] [All Lists]

RE: how to do i18n with parameter substitution

2005-03-23 04:12:51
After sleeping on it I was able to answer my own question, however I suspect
that that p1 and p2 templates could be generalised to handle any named
parameter, but haven't figured that out yet.

  <xsl:template name='i18n'>
    <xsl:param name='caption'/>
    <xsl:choose>
      <xsl:when
test='document("phrases.xml")/phrases/phrase/target[../@key=$caption/@key
and lang($language)]'>
        <xsl:apply-templates
select='document("phrases.xml")/phrases/phrase/target[../@key=$caption/@key
and lang($language)]' mode='parameters'>
          <xsl:with-param name='caption' select='$caption'/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select='$caption' />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match='target' mode='parameters'>
    <xsl:param name='caption'/>
    <xsl:apply-templates mode='parameters'>
      <xsl:with-param name='caption' select='$caption'/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match='p1' mode='parameters'>
    <xsl:param name='caption'/>
    <xsl:value-of select='$caption/p1/@value'/>
  </xsl:template>

  <xsl:template match='p2' mode='parameters'>
    <xsl:param name='caption'/>
    <xsl:value-of select='$caption/p2/@value'/>
  </xsl:template>

George
(Note to self: get more sleep).



-----Original Message-----
From: George James [mailto:GeorgeJ(_at_)georgejames(_dot_)com]
Sent: 23 March 2005 02:56
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: [xsl] how to do i18n with parameter substitution


I have a template that does language substitution for text
strings.  I want to extend this to be able to pass in a
variable number of parameter values that get substituted into
placeholder in each language string.

The current template looks something like this:

  <xsl:template name='i18n'>
    <xsl:param name='caption'/>
    <xsl:choose>
      <xsl:when
test='document("phrases.xml")/phrases/phrase/target[../@key=$c
aption and lang($language)]'>
        <xsl:copy-of
select='document("phrases.xml")/phrases/phrase/target[../@key=
$caption and lang($language)]' />
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select='$caption' />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

I have a phrases.xml document that looks like this:

<phrase key='Client not on file'>
 <target xml:lang='en'>Client number <p1/> not on file.
Priority: <p2/></target>  <target xml:lang='de'>Priorität:
<p2/>. Klient Nr. <p1/> nicht auf Akte.</target> </phrase>

How can I extend my template so that will take as input
something like the
following:

<caption key='Client not on file'>
 <p1 value='123456'/>
 <p2 value='99'/>
</caption>

and produce one of the following strings, depending on the
language: Client number 123456 not on file. Priority: 99
Priorität: 99. Klient Nr. 123456 nicht auf Akte.

Can anyone help me with this?
George




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>