473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Generating multiple XHTML pages from an XML file

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


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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Michele Simionato | last post by:
What is the recommended way of generating HTML from Python? I know of HTMLGen and of few recipes in the Cookbook, but is there something which is more or less standard? Also, are there plans to...
2
by: Tristan Miller | last post by:
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...
35
by: The Bicycling Guitarist | last post by:
My web site has not been spidered by Googlebot since April 2003. The site in question is at www.TheBicyclingGuitarist.net/ I received much help from this NG and the stylesheets NG when updating the...
32
by: jp29 | last post by:
My take on problems composing, serving and rendering XHTML documents/web pages: 1. Typical conscientious web authors are producing XHTML documents (Web pages) that feature valid Markup and with...
21
by: Sandy | last post by:
Hello - I am using Visual Studio .Net. I need an example of how to construct a class that can be used throughout a project where I can include its subs and functions in various pages in the...
4
by: Lee Chapman | last post by:
Hi, I am having difficulty getting the ASP.NET framework to generate valid XHTML. My immediate problem surrounds user input in, for example, textbox controls. I consider characters such as...
22
by: Gianni Rondinini | last post by:
hi all. please excuse the misusage of some tech terms, but writing in english is not as easy as in italian :) i'm designing our new website and, since i want to do something that will last as...
24
by: Dan Jacobson | last post by:
I shall jump on the XHTML bandwagon. I run my perfectly good html4/strict pages thru $ tidy -asxhtml -utf8 #to get: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.