Re: Trying to load Entity file

Subject: Re: Trying to load Entity file
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 8 Nov 2000 11:04:19 +0000
Ken,

> I am trying to load an entity file into my XML file. The entity file
> will be located in various directories specified with a directory
> name. The directory name can be found in cookies, variables, etc...
> How can I do this?

As Mike said, XML entities are off topic for this mailing list, but
the XSLT document() function gives you another way of accessing
information in remote files, and it may be that you can use this to
your advantage.

With this method, the source XML file would hold the general
information common to all languages.  The XSLT would combine this
general information with specific information about the captions to
use in different languages.

The language to be generated on a particular run of the stylesheet can
be set using a stylesheet parameter declared at the top level of the
stylesheet with the xsl:param element:

<xsl:param name="lang" select="'en'" />

To use this technique, you need to define the captions for different
languages in XML rather than as ENTITY definitions. So, for example,
you might have a file that contains:

--- caption.xml ---
<captions xml:lang="en">
  <control id="Tab_2dControls">
    <caption>English Caption</caption>
    <caption xml:lang="fr">French Caption</caption>
    <caption xml:lang="de">German Caption</caption>
    ...
  </control>
  ...
</captions>
---

This file is accessible within an XSLT stylesheet with the function
call:

  document('caption.xml')

You can keep the node set holding these captions in a global variable
for easy access throughout your stylesheet:

<xsl:variable name="captions"
              select="document('caption.xml')/captions" />
  
Then, the caption for a particular control in a particular language
can be accessed using:

  $captions/control[@id = $control]/caption[lang($lang)]

(or, more efficiently, you could use a key to retrieve the control
that you're after).

This has the advantage of only having to maintain 2 source XML files:
one holding the common information and the other holding the
translations (you could even merge them into one if you want).  Also,
XML is a bit easier to edit than entity definitions, and more
reusable.

I hope that gives you some ideas for a different approach,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread