Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result XSLT.
Localizing XML documents (at source level) using XSLT
description
Transcript of Localizing XML documents (at source level) using XSLT
AI'2003 Software Engineering 1
Localizing XML documents (at source level) using XSLT
Presented by: Yijun [email protected]://cxsl.sourceforge.net
AI'2003 Software Engineering 2
Overview
1. Motivated by an example
2. Localizing engine: an XSL style sheet
3. XML documents localized HTML, XSL, DocBook, etc.
4. Applications of l10n and i18n1. Program source code localization
2. Document localization
5. Summary
6. Future work
AI'2003 Software Engineering 3
1.1 An HTML document
<html>
<head>
<title>A HTML document</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
English words
Hyper Text Markup Language
English tag
AI'2003 Software Engineering 4
<html> <head> <title>HTML文档 </title> </head> <body> <h1>你好,世界! </h1> </body></html>
English tags
Chinese characters
1.2 Presentation level localization
AI'2003 Software Engineering 5
1.3 Source level localization
Presentation level localization still requires user’s competence in English to express the HTML tags
Source level localization is feasible, because: HTML can be represented using XHTML, which is a
dialect of XML XML allows unicode tags and attributes Given a mapping dictionary, XSLT can transform
one set of tags/attributes into another language
AI'2003 Software Engineering 6
LocalizeXSLT
SOURCEXML document
in English:
XHTMLXSL…
HTML
XSL CXSL
CHTML
…………
dictionary
TARGETlocalized
XML document:
CHTMLCXSL
…
2. The localizing engine
AI'2003 Software Engineering 7
stylesheet
output method=“xml” indent=“yes”
Name spaces:xmlns:xslxmlns:&source;xmlns:⌖
Entities:&source;⌖&dictionary;
template match=“/”
template match=“&source;:*”
template name=“translate-element”
template name=“filter”
template name=“filter-string”
apply-templatesselect=“&source;:*”
for-each element call-template
for-each ”axis::”, “function(“ call-template
$node, $tag
$attr
for-each attribute call-template
LocalizeXSLT
$str
AI'2003 Software Engineering 8
2. (cont) using a dictionary
<dictionary>
<entry type=“element”>
<html>HTML</html>
<chtml>超文本标注语言 </chtml>
</entry>
…
</dictionary>
AI'2003 Software Engineering 9
3. XML document localized
<超文本标注语言 > <文本首 > <标题 >超文本文档 </标题 > </文本首 > <文本体 > <标题一 >你好,世界! </标题一 > </文本体 ></超文本标注语言 >
Chinese tags
Chinese characters
AI'2003 Software Engineering 10
Demo 1
Inversing the source-target namespace, the same localizing XSLT can be regarded as an internationalizing XSLT
C:>xsltproc l10n.xsl l10n.xsl> l10n.xmlC:>xsltproc i10n.xsl l10n.xml> i18n.xml
The localization (l10n) and internationalization (i18n) at source level instead of presentation level makes the translation thorough
AI'2003 Software Engineering 11
4. Applications
1. Source code localization C, Java, Fortran, PL/IX, etc.
2. Documentation localization LaTeX, RTF, PDF, Postscript, etc.
AI'2003 Software Engineering 12
4.1 Source code localization
Program source code level localization Given the program grammar in YACC, the
program syntax tree can be automatically XMLized into an XML document using YAXX
The localization of the generated XML leads to a localized program after applying another XSLT transformation
AI'2003 Software Engineering 13
LocalizeXSLT
A program in localized L
An XML syntax tree
A program in L, e.g. C program, or localized C
A YACC grammar of a language L, e.g.
ANSI C, YACC, …
Parser for L
YACC YAXX
Localized XML syntax tree
Code generationXSLT
AI'2003 Software Engineering 14
Demo 2 (offline)
ANSIC grammar in YACC An example C program Syntax XML document and DTD generated by
YAXX, in “ansic-dictionary.xml”, the <yaxx> entries can be generated from YAXX too
The localized CYAXX document The code generation XSLT’s for YAXX and
CYAXX outputs identical program because the leaf tokens are the same! One can also choose to localize the text() content.
AI'2003 Software Engineering 15
LocalizeXSLT
DocBook
DB2LaTeXXSLT
LocalizedDocBook
LaTeX CJK LaTeX
DB2CLaTeXXSLT
4.2 DocBook localization
AI'2003 Software Engineering 16
Demo 3 (offline)
The DocBook version of the paper Clues for LaTeX users
Tricks of using DocBook to write an article \usepackage{CJKLatex} for localized Chinese-
Japanese-Korean LaTeX users openjade is a SGML tool that converts
DocBook into LaTeX and HTML. It is chosen for the HTML generation of the paper.
db2Latex is a set of XSL stylesheets, they are adapted to use CJKLaTeX with minor changes.
AI'2003 Software Engineering 17
5. Summary
L10n & i18n through an XSLT style sheet Separate multi-lingual dictionaries from the
common automatic XSLT translator The localization is at the source level instead
of at the presentation level Not only the XML dialects (HTML, XSL,
DocBook, etc. ) can be localized, an arbitrary programming language can be as well
Helps not only web-designers, but also programmers and document authors
AI'2003 Software Engineering 18
6. Future work
Future improvementsOne-to-many translation selection using
context cluesText2speech markup and translationsConsider natural language translation
We hope someday the Unite Nations will use a similar tool to process multi-lingual speeches and documents