Re: localization techniques and code review

Subject: Re: localization techniques and code review
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 17 Nov 2000 17:04:27 +0000

> 1. Am I on the right track? What about the use of nested
> <xsl:for-each select="document('localization.xml')">

Looks like you are. There's one small error, in that you're using
xsl:param immediately within an xsl:for-each - that needs to be an
xsl:variable instead. The other small thing is that having assigned
the root node of the 'localization.xml' document to the 'trans'
variable, you may as well use it again instead of reaccessing the
document in the xsl:for-each. You also don't have to search all the
root descendants for the 'field' elements: they're all direct children
of 'page' (at least in this example).

In other words, change it to:

  <xsl:for-each select="field">
    <xsl:variable name="field" select="." />
    <xsl:value-of select="$field" />
      <xsl:for-each select="$trans">
            select="key('translate',concat($field,'-',$selectLang))" />

The nested xsl:for-each is necessary.  The key() function that you use
is scoped by the current node: it only looks for nodes within the
current document.  In the outer xsl:for-each, the current document is
your source XML.  You need to change it to the localization.xml
document to use the key to retrieve information quickly from it.

> 2. What if I need to re-print the table again? Could I have somehow
> stored the results of the document() call to be able to reuse it at
> a later stage?

Not within XSLT.  It really depends on your set up, how you're
processing the XSLT on the server.  It may be possible for the server
to keep the DOM for the localization.xml document cached so that it
doesn't have to parse it each time.  Perhaps a Cocoon person can give
you a better answer.

Sorry I can't be more help,


Jeni Tennison

 XSL-List info and archive:

Current Thread