XML Templates

Sample Template

<div>

  <d:def function="myfunction()">
    <p>Some text!!</p>
  </d:def>

  <d:if test="$heading">
    <h1>A heading</h1>
  </d:if>

  <d:def function="mySecondFunction(heading)">
    <h1>_{$heading}</h1>
  </d:def>
  
  <ul>
    <d:for each="$x in $items">
      <li>_{$x}</li>
    </d:for>
  </ul>

  <ul>
    <d:for each="$n in $names">
      <li>_{$n.first} _{$n.last}, _{$n.somenumber}, _{$n.date|datetime, long}</li>
    </d:for>
  </ul>

  My first function call: _{myfunction()}

  My second function call: _{mySecondFunction("My Heading")}

</div>

Sample Usage

import tango.io.Stdout, tango.util.time.DateTime;
import sendero.xml.XmlTemplate;

class Name
{
	this() {}
	this(char[] first, char[] last, uint n, DateTime date)
	{
		this.first = first; this.last = last;
		this.somenumber = n; this.date = date;
	}
	uint somenumber;
	char[] first, last;
	DateTime date;
}

void main()
{
	char[][] items;
	items ~= "hello";
	items ~= "world";
	
	Name[] names;
	names ~= new Name("Jackie", "Smith", 7654321, DateTime(1942, 10, 14));
	names ~= new Name("Joe", "Schmoe", 1354, DateTime(1967, 3, 3));
	
	auto t = XmlTemplate.get("mytemplate.xml");
	t["items"] = items;
	t["names"] = names;	
	Stdout(t.render);
}

Sample Output

<div>

  <ul>
   <li>hello</li>
   <li>world</li>
  </ul>

  <ul>
    <li>
      Jackie Smith, 7654321, 10/14/1942 12:00:00 AM
    </li>
    <li>
      Joe Schmoe, 1354, 3/3/1967 12:00:00 AM
    </li>
  </ul>

  My first function call: <p>Some text!!</p>
  
  My second function call: <h1>My Heading</h1>

</div>