By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 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+
4 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

P: n/a
Greetings.

In article <3f********@olaf.komtel.net>, Martin Honnen wrote:
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:


OK, so I take it, then, that XSLT by default can't specify different output
streams, and that I would need to use a shell script to invoke the XSLT
processor on the stylesheet and source file n separate times (i.e., once
for each output language). Correct?

Thanks for the sample stylesheet; this is pretty much the sort of example I
was looking for to help get me started.

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 #4

P: n/a


Tristan Miller wrote:
In article <3f********@olaf.komtel.net>, Martin Honnen wrote:
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:

OK, so I take it, then, that XSLT by default can't specify different output
streams, and that I would need to use a shell script to invoke the XSLT
processor on the stylesheet and source file n separate times (i.e., once
for each output language). Correct?


With XSLT 1.0 you can't have different output streams and you would
indeed have to call the XSLT processor on the stylesheet and the source
file passing in the the language as a parameter and do that for each
language.
However some processors (like Saxon for instance) have extensions to
produce multiple output files in one pass.

--

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

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.