By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,222 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,222 IT Pros & Developers. It's quick & easy.

Generating multiple XHTML pages from an XML file

P: n/a
Greetings.

I would like to produce a static multilingual website in XHTML. Is it
possible to specify each web page in its own XML file, but have all of the
translations encapsulated in that one file, and then process each XML file
to generate separate language-variant XHTML files?

For example, say we have a file foo.xml which contains, in part, something
like the following:

<body>
<h1>
<only lang="de">Guten Tag!</only>
<only lang="en">Hello!</only>
<only lang="hu">Jó napot kivánok!</only>
<only lang="fr">Bonjour!</only>
</h1>
</body>

I want to be able to run some simple command-line utility which will
automatically generate four separate XHTML files foo.de.html, foo.en.html,
foo.hu.html, and foo.fr.html, containing, respectively,

<body>
<h1>
Guten Tag!
</h1>
</body>

<body>
<h1>
Hello!
<h1>
</body>

And so on.

If this is possible, how do I go about doing this, and what software do I
need? (I am running a GNU/Linux system.)

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Tristan Miller wrote:
Greetings.

I would like to produce a static multilingual website in XHTML. Is it
possible to specify each web page in its own XML file, but have all of the
translations encapsulated in that one file, and then process each XML file
to generate separate language-variant XHTML files?

For example, say we have a file foo.xml which contains, in part, something
like the following:

[snip]

I want to be able to run some simple command-line utility which will
automatically generate four separate XHTML files foo.de.html, foo.en.html,
foo.hu.html, and foo.fr.html, containing, respectively,

[snip]

And so on.

If this is possible, how do I go about doing this, and what software do I
need? (I am running a GNU/Linux system.)


Use XSLT.
--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #2

P: n/a


Tristan Miller wrote:
I would like to produce a static multilingual website in XHTML. Is it
possible to specify each web page in its own XML file, but have all of the
translations encapsulated in that one file, and then process each XML file
to generate separate language-variant XHTML files?

For example, say we have a file foo.xml which contains, in part, something
like the following:

<body>
<h1>
<only lang="de">Guten Tag!</only>
<only lang="en">Hello!</only>
<only lang="hu">Jó napot kivánok!</only>
<only lang="fr">Bonjour!</only>
I suggest to use e.g.
<only xml:lang="de">
as the xml:lang attribute is the way the XML standards suggest the
language of an element's content should be specified.
I want to be able to run some simple command-line utility which will
automatically generate four separate XHTML files foo.de.html, foo.en.html,
foo.hu.html, and foo.fr.html, containing, respectively,

<body>
<h1>
Guten Tag!
</h1>
</body>
If this is possible, how do I go about doing this, and what software do I
need? (I am running a GNU/Linux system.)


Transforming XML files is easily done with XSLT, there are several XSLT
processors implemented in Java, some of which have command line
interfaces, for instance Saxon:
http://saxon.sourceforge.net/

Of course you need an XSLT stylesheet that takes the language as a
parameter, for instance the following XSLT stylesheet just copies all
nodes besides <only> element nodes for which only the content is copied
if the xml:lang attribute matches the outputLanguage parameter:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="UTF-8" />

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

<xsl:template match="only[lang($outputLanguage)]">
<xsl:apply-templates select="node()" />
</xsl:template>

<xsl:template match="only" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
The stylesheet is set to produce HTML output but if needed it can also
produce XHTML.

Followup-To comp.text.xml
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.