]> git.sesse.net Git - xml-template/blobdiff - doc/intro.txt
Add a proper wrapper for php5-swig, which also makes attribute[23] pass. All tests...
[xml-template] / doc / intro.txt
index a5d1dede4511be796cd7d90dabeb3389b22a8cbe..b727bfffa1e47faf9b8abed809f1d973465806ae 100644 (file)
@@ -16,12 +16,13 @@ favourite distribution and do "bzr get http://bzr.sesse.net/xml-template/"
 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">
@@ -47,6 +48,7 @@ Code (simple.pl):
 
 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>
@@ -80,17 +82,18 @@ We move on to another useful operation, cloning.
 
 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">
-  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:tmpl="http://template.sesse.net/" xml:lang="en">
+  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://template.sesse.net/" xml:lang="en">
     <head>
       <title>Cloning test</title>
     </head>
     <body>
-       <p>My favourite color is <tmpl:color />; I like that very much.
+       <p>My favourite color is <t:color />; I like that very much.
          All my favourite things:</p>
-      <ul tmpl:id="things">
+      <ul t:id="things">
         <li />
       </ul>
     </body>
@@ -114,6 +117,7 @@ Code (clone.pl):
 
 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>
@@ -135,7 +139,7 @@ Result:
   </html>
 
 This isn't much harder than the example above; we've done a simple replacement
-of the contents of <tmpl:color> to "blue" (and after that just removed the tag;
+of the contents of <t:color> to "blue" (and after that just removed the tag;
 any tag you use in the templating namespace will automatically get stripped
 away), and then cloned the contents of our "things" bullet list. Note that
 XML::Template automatically recurses after the cloning, since you probably
@@ -166,17 +170,18 @@ we have a small hack:
 
 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">
-  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:tmpl="http://template.sesse.net/" xml:lang="en">
+  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://template.sesse.net/" xml:lang="en">
     <head>
       <title>Cloning test</title>
     </head>
     <body>
-       <p>My favourite color is <tmpl:color />; I like that very much.
-         All my favourite things:</p>
-      <ul tmpl:id="things">
+      <p>My favourite color is <t:color />; I like that very much.
+        All my favourite things:</p>
+      <ul t:id="things">
         <li />
       </ul>
     </body>
@@ -190,16 +195,17 @@ Code (attribute.pl):
   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>
@@ -248,9 +254,15 @@ The main thoughts behind XML::Template have been, in no particular order:
    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