Changes between Version 2 and Version 3 of XML/Templates


Ignore:
Timestamp:
Nov 24, 2013, 1:08:03 PM (8 years ago)
Author:
vadim.godunko
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • XML/Templates

    v2 v3  
    55Markup Templates Engine reads XML template documents and generates XML or HTML5/XHTML5 documents.
    66
    7 == Template Directives ==
     7== XML Template Language ==
    88
    9 === Conditional Sections ===
     9=== Template Directives ===
    1010
    11 ==== mtl:if ====
     11==== Conditional Sections ====
     12
     13===== mtl:if =====
    1214
    1315{{{#!xml
    14 <mtl:if condition="boolean expression">
     16<mtl:if test="boolean_parameter">
    1517  ...
    1618</mtl:if>
    1719}}}
    1820
    19 === Looping ===
     21==== Looping ====
    2022
    21 ==== mtl:for ====
     23===== mtl:for =====
    2224
    2325{{{#!xml
     
    2729}}}
    2830
    29 == Expressions ==
     31=== Expressions ===
    3032
    31 === Simple expressions ===
     33==== Simple expressions ====
    3234
    33 === Iterating expressions ===
     35{{{
     36<variable>
     37}}}
     38
     39{{{
     40<variable>.<member>
     41}}}
     42
     43==== Iterating expressions ====
     44
     45{{{
     46<variable> in <array_variable>
     47}}}
     48
     49== Use template processor in application ==
     50
     51To use Template Processor in application it need to be connected to SAX content and lexical events source (for instance to XML_Simple_Reader) and to SAX content and lexical events consumer (for instance to XML_Pretty_Writer of HTML5_Writer).
     52
     53Application defines set of parameters by XML_Template_Processor's Set_Parameter subprogram. Values are passed using holders mechanism. Supported types are:
     54
     55||= Type =||= Holder package =||= Comment =||
     56|| boolean             || League.Holders.Booleans       || used as condition in 'if' directives ||
     57|| string              || League.Holders                || substituted literally inside character data and attribute value ||
     58|| markup event stream || XML.Templates.Streams.Holders || substituted as SAX event stream inside character data ||
     59|| JSON object         || League.Holders.JSON_Objects   || members are accessible by selector expression ||
     60|| JSON array          || League.Holders.JSON_Array     || elements are accessible by 'for' directive ||
     61
     62Here is small example, it reads page.xml.tmpl file, process it end outputs result to standard output.
     63
     64{{{#!ada
     65with Ada.Wide_Wide_Text_IO;
     66
     67with League.Holders.Booleans;
     68with League.Holders.JSON_Arrays;
     69with League.JSON.Arrays;
     70with League.JSON.Objects;
     71with League.JSON.Values;
     72with League.Strings;
     73with XML.SAX.Input_Sources.Streams.Files;
     74with XML.SAX.Output_Destinations.Strings;
     75with XML.SAX.Pretty_Writers;
     76with XML.SAX.Simple_Readers;
     77with XML.Templates.Processors;
     78
     79procedure Main is
     80   Input  : aliased XML.SAX.Input_Sources.Streams.Files.File_Input_Source;
     81   Reader : aliased XML.SAX.Simple_Readers.SAX_Simple_Reader;
     82   Filter : aliased XML.Templates.Processors.Template_Processor;
     83   Writer : aliased XML.SAX.Pretty_Writers.SAX_Pretty_Writer;
     84   Output : aliased XML.SAX.Output_Destinations.Strings.SAX_String_Output_Destination;
     85   Post   : League.JSON.Objects.JSON_Object;
     86   Posts  : League.JSON.Arrays.JSON_Array;
     87
     88begin
     89   Input.Open_By_File_Name
     90    (League.Strings.To_Universal_String ("page.xml.tmpl"));
     91
     92   --  Configure reader.
     93
     94   Reader.Set_Input_Source (Input'Unchecked_Access);
     95   Reader.Set_Content_Handler (Filter'Unchecked_Access);
     96   Reader.Set_Lexical_Handler (Filter'Unchecked_Access);
     97
     98   --  Configure template processor.
     99
     100   Filter.Set_Content_Handler (Writer'Unchecked_Access);
     101   Filter.Set_Lexical_Handler (Writer'Unchecked_Access);
     102
     103   Filter.Set_Parameter
     104    (League.Strings.To_Universal_String ("title"),
     105     League.Holders.To_Holder
     106      (League.Strings.To_Universal_String ("Page title")));
     107   Filter.Set_Parameter
     108    (League.Strings.To_Universal_String ("is_admin"),
     109     League.Holders.Booleans.To_Holder (True));
     110
     111   Post.Insert
     112    (League.Strings.To_Universal_String ("user"),
     113     League.JSON.Values.To_JSON_Value
     114      (League.Strings.To_Universal_String ("first")));
     115   Post.Insert
     116    (League.Strings.To_Universal_String ("post"),
     117     League.JSON.Values.To_JSON_Value
     118      (League.Strings.To_Universal_String
     119        ("This is first post from first user")));
     120   Posts.Append (Post.To_JSON_Value);
     121   Post.Insert
     122    (League.Strings.To_Universal_String ("user"),
     123     League.JSON.Values.To_JSON_Value
     124      (League.Strings.To_Universal_String ("second")));
     125   Post.Insert
     126    (League.Strings.To_Universal_String ("post"),
     127     League.JSON.Values.To_JSON_Value
     128      (League.Strings.To_Universal_String
     129        ("This is first post from second user")));
     130   Posts.Append (Post.To_JSON_Value);
     131   Filter.Set_Parameter
     132    (League.Strings.To_Universal_String ("posts"),
     133     League.Holders.JSON_Arrays.To_Holder (Posts));
     134
     135   --  Configure XML writer.
     136
     137   Writer.Set_Output (Output'Unchecked_Access);
     138
     139   --  Process template.
     140
     141   Reader.Parse;
     142
     143   --  Output result.
     144
     145   Ada.Wide_Wide_Text_IO.Put (Output.Get_Text.To_Wide_Wide_String);
     146end Main;
     147}}}
     148
    34149
    35150== Generating of HTML5 Documents ==