Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Generating multiple XHTML pages from an XML file

Reply
Thread Tools

Generating multiple XHTML pages from an XML file

 
 
Tristan Miller
Guest
Posts: n/a
 
      12-19-2003
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
 
Reply With Quote
 
 
 
 
Anne van Kesteren
Guest
Posts: n/a
 
      12-19-2003
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/>
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-19-2003


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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="html" encoding="UTF-8" />

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

 
Reply With Quote
 
Tristan Miller
Guest
Posts: n/a
 
      12-19-2003
Greetings.

In article <3fe2eb60$(E-Mail Removed)>, 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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-19-2003


Tristan Miller wrote:

> In article <3fe2eb60$(E-Mail Removed)>, 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How *extract* data from XHTML Transitional web pages? got xml.dom.minidom troubles.. seberino@spawar.navy.mil Python 4 03-03-2007 01:46 AM
generating web pages from XML Vicente García ASP .Net 6 02-03-2007 03:03 PM
Should I Convert Site To XHTML or XHTML mobile? chronos3d HTML 9 12-05-2006 04:46 PM
parse URL (href) from xhtml, xhtml -> text, for data hawat.thufir@gmail.com XML 7 02-08-2006 07:39 PM
Test pages served as html, xhtml, and xml cwdjrxyz HTML 19 01-20-2006 08:31 AM



Advertisments