cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject [2.1] Non-trivial uses of i18n transformer
Date Mon, 23 May 2016 13:31:25 GMT
Hash: SHA1


I'm finally getting around to internationalizing the XSLT-based parts
of my application, and I'm running into a problem with non-trivial
uses of <i18n:text> in a template.

Here's an excellent example of the kind of thing I'm having trouble
with. I have a single XML document going through a pipeline with a few
transformations in it. There is one major transform where pretty much
everything interesting happens. I'd like to use <i18n> in there to
produce an HTML <a> element with a localized "title" attribute.
Something like this:

<xsl:template match="p:foo">
  <a href="..." title="This is some English text">click me</a>

Localizing the "click me" text is trivial. Doing the same with the
"title" attribute is not.

   <a title="<i18n:text key="some.text" />"  [...] >

That obviously won't work because the attribute won't be parsed and
evaluated by the XSLT parser. Use of {} around it doesn't work because
it's an element, not an expression.

  <xsl:element name="a">
    <xsl:attribute name="title">
      <i18n:text key="some.text" />

That doesn't work because <xsl:attribute> evidently can't contain
<i18n:text>. At first, this irritated me but then I realized that this
would never work, because the second case would basically degenerate
into the first case after the <map:transform> completed its work for
this template before I (later) ran the I18nTransformer.

The only idea I've had is to flip the current i18n process on its head
and instead do this:

  <map:match pattern="/foo">
    <map:generate src="my.xml.document.xml" />

    <map:transform src="cocoon://localized-transform.xsl" />

    <map:serialize />

  <map:match pattern="/localized-transform.xsl">
    <map:generate src="original.xsl" />

    <map:transform type="i18n">
      <map:parameter name="locale" value="en_US" />

    <map:serialize />

So instead of transforming the input document with an
internationalized stylesheet, then transforming the result with the
i18n transformer, I first transform the transformer itself to get a
localized transformer, and transform the input document with *that*.

Is that "recommended technique"? Alternatively, is that entirely stupid?

If this is a good idea, how specifically can I accomplish what I have
above? I haven't yet tried it, but I'm concerned I'll have the same
problem with elements not being allowed in other elements.

Any suggestions?

- -chris
Comment: GPGTools -
Comment: Using GnuPG with Thunderbird -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message