to check out the code and this documentation.
There is a lot to be said about design philosophy, but let's first give a
-simple example to give you the feel of how it works. (The example is in
-Perl, but there's also a functionally equivalent PHP version, and more
-languages should probably come soon.)
+simple example to give you the feel of how it works. (The example is in Perl,
+but there are also functionally equivalent PHP, Python, Ruby and C++11
+versions; ports to other languages would be welcome.)
Template (simple.xml):
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Result:
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
Template (clone.xml):
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Result:
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
Template (clone.xml), repeated for your convenience:
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
my $doc = XML::Template::process_file('../xml/clone.xml', {
'color' => 'red',
'#things' => [
- { 'li' => 'Raindrops on roses', 'li.class' => 'odd' },
- { 'li' => 'Whiskers on kittens', 'li.class' => 'even' },
- { 'li' => 'Bright copper kettles', 'li.class' => 'odd' },
- { 'li' => 'Warm, woolen mittens', 'li.class' => 'even' }
+ { 'li' => 'Raindrops on roses', 'li/class' => 'odd' },
+ { 'li' => 'Whiskers on kittens', 'li/class' => 'even' },
+ { 'li' => 'Bright copper kettles', 'li/class' => 'odd' },
+ { 'li' => 'Warm, woolen mittens', 'li/class' => 'even' }
]
});
print $doc->toString;
Result:
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
than only supporting one language or having someting that needs to reimplement
the entire DOM with wrappers for each language. (Thankfully, by relying on
the DOM support in each language, the code so far is under 200 lines per
- implementation, so maintaining this hopefully shouldn't be much work.)
- As proof-of-concept, I've got Perl and PHP implementations that work and
- feel largely the same -- Python, Ruby and other implementations are welcome.
+ implementation, so maintaining this hopefully shouldn't be much work.) As
+ proof-of-concept, there are got Perl, PHP, Python, Ruby and C++11
+ implementations that work and feel largely the same (and even a SAX-based Perl
+ implementation, for larger trees that won't fit into memory) -- other
+ implementations are welcome. This is backed up by a test suite, which
+ ensures that all the different implementations return structurally
+ equivalent XML for a certain set of test cases. Porting to a new language
+ is not difficult, and once you've got all the test cases to pass, your
+ work is most likely done.
As a side note to the second point, I've spent some time wondering exactly
_why_ you want to separate the back-end logic from your HTML, and why people
More to come here at some point, probably. Now, go out and just _use_ the
thing -- I hope it will make your life on the web simpler. :-)
- - Steinar H. Gunderson <sgunderson@bigfoot.com>, http://www.sesse.net/
+ - Steinar H. Gunderson <steinar+xmltemplate@gunderson.no>, http://www.sesse.net/