<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>XUL</title><link>http://blogs.acceleration.net/russ/category/40.aspx</link><description>XUL related posts</description><managingEditor>Russ</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Russ</dc:creator><title>XUL Repeater</title><link>http://blogs.acceleration.net/russ/archive/2005/05/04/1063.aspx</link><pubDate>Wed, 04 May 2005 16:24:00 GMT</pubDate><guid>http://blogs.acceleration.net/russ/archive/2005/05/04/1063.aspx</guid><description>I had talked about this repeater control a while back but then got distracted onto other things.&lt;br /&gt;
&lt;a href="http://blogs.acceleration.net/russ/articles/1062.aspx"&gt;Go Here to see  the Repeater Source&lt;/a&gt;
&lt;br /&gt;
It probably can easily be ported to work with just javascript and HTML but I havnt had the time or need to do so yet.  Who knows maybe soon.

UPDATE: Fixed Link&lt;img src ="http://blogs.acceleration.net/russ/aggbug/1063.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml">I had talked about this repeater control a while back but then got distracted onto other things.<br />
<a href="http://blogs.acceleration.net/russ/articles/1062.aspx">Go Here to see  the Repeater Source</a>
<br />
It probably can easily be ported to work with just javascript and HTML but I havnt had the time or need to do so yet.  Who knows maybe soon.

UPDATE: Fixed Link<img src ="http://blogs.acceleration.net/russ/aggbug/1063.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Russ</dc:creator><title>The XBL Template / Repeater control</title><link>http://blogs.acceleration.net/russ/archive/2005/04/10/819.aspx</link><pubDate>Sun, 10 Apr 2005 17:04:00 GMT</pubDate><guid>http://blogs.acceleration.net/russ/archive/2005/04/10/819.aspx</guid><description>So I finally found a palatable solution to the &lt;a href="http://blogs.acceleration.net/russ/archive/2005/04/06/804.aspx"&gt;Templates Problem&lt;/a&gt; I talked about earlier.  The technique I used was to create a XBL control called 'repeater'.  &lt;a title="Ryan" href="http://blogs.acceleration.net/ryan/"&gt;Ryan&lt;/a&gt; had some issues with the word template as I was using it so we switched over to repeater to be less ambiguous.  The goal of this is not to provide a general control system (which XBL and &lt;a title="xbl alternative" href="http://www.jerf.org/resources/xblinjs/" target="_blank"&gt;XBLinJS&lt;/a&gt; try to do), but only to provide the functionality to easily repeat nodes inside of a valid tag.  The best example I can give for this is for  binding a dropdownlist / select box / menupopup, where I just need to repeat the &amp;lt;menuitem /&amp;gt; over a flat set of data.  
&lt;br /&gt;&lt;br /&gt;
var testTable = [['id', 'name'],&lt;br /&gt;
 [ 1, 'Programmers' ],&lt;br /&gt;
 [ 2, 'WebAdmin' ],&lt;br /&gt;
 [ 3, 'Broadband']];&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hbox&amp;gt;&lt;br /&gt;
  &amp;lt;repeater&amp;gt;&lt;br /&gt;
    &amp;lt;label value="{name}" /&amp;gt;&lt;br /&gt;
  &amp;lt;/repeater&amp;gt;&lt;br /&gt;
&amp;lt;/hbox&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the 'repeater' control does is remove the repeater node from its parent storing a reference to this 'template' on that control (so we have what was there but none of it is rendered).  Then it loops through the data set adding all of the nodes that were inside of the repeater tags, with their values filled in.  So what gets rendered to the page would be this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hbox&amp;gt;&lt;br /&gt;
    &amp;lt;label value="Programmers" /&amp;gt;&lt;br /&gt;
    &amp;lt;label value="WebAdmin" /&amp;gt;&lt;br /&gt;
    &amp;lt;label value="Broadband" /&amp;gt;&lt;br /&gt;
&amp;lt;/hbox&amp;gt;&lt;br /&gt;
&lt;br /&gt;

The really nice part about this system is that by inserting a repeater node inside of the template, with the outer template filling in the datasource attribute for the inner repeater as it goes, allows you to chain these repeaters to make hierarchical data repeaters.   After I finish polishing everything and test it once more, I am going to port this to use &amp;lt;div repeater="true" &amp;gt; [enter repeated data here]&amp;lt;/div&amp;gt; so that I can achieve the same repeater functionality in standard HTML.   
&lt;br /&gt;&lt;br /&gt;
Overall this has been my best experience with XBL, most notable because it required only one function block and one line of xbl content binding  ( the &amp;lt;children /&amp;gt; node).  It did however force me to copy code in and out of the xbl document to a standard JS doc to get parse errors to show up (Mozilla was just silently failing when their was a parse error in the XBL Javascript). 
&lt;br /&gt;&lt;br /&gt;
&lt;a title="Ryan" href="http://blogs.acceleration.net/ryan/"&gt;Ryan&lt;/a&gt; will probably give us a little preview of his js control scheme based of his interpretations of &lt;a title="xbl alternative" href="http://www.jerf.org/resources/xblinjs/" target="_blank"&gt;XBLinJS&lt;/a&gt;.  What it seems we've got almost worked out is a simple way to repeat nodes and a simple way to create complex, repeatable, XUL/HTML controls.  Most of this work was inspired by excessive frustration (mostly caused by nonexistant error handling) at the way mozilla handles these two things  and by reading &lt;a href="http://www.jerf.org"&gt;Jeremy Bowers&lt;/a&gt; site which convinced us to do what we already wanted to do.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
UPDATE:&lt;br /&gt;
&lt;a href="http://blogs.acceleration.net/russ/articles/1062.aspx"&gt;Go Here to see  the Repeater Source&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://blogs.acceleration.net/russ/articles/1145.aspx"&gt;Usage Example&lt;/a&gt;&lt;img src ="http://blogs.acceleration.net/russ/aggbug/819.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml">So I finally found a palatable solution to the <a href="http://blogs.acceleration.net/russ/archive/2005/04/06/804.aspx">Templates Problem</a> I talked about earlier.  The technique I used was to create a XBL control called 'repeater'.  <a title="Ryan" href="http://blogs.acceleration.net/ryan/">Ryan</a> had some issues with the word template as I was using it so we switched over to repeater to be less ambiguous.  The goal of this is not to provide a general control system (which XBL and <a title="xbl alternative" href="http://www.jerf.org/resources/xblinjs/" target="_blank">XBLinJS</a> try to do), but only to provide the functionality to easily repeat nodes inside of a valid tag.  The best example I can give for this is for  binding a dropdownlist / select box / menupopup, where I just need to repeat the &lt;menuitem /&gt; over a flat set of data.  
<br /><br />
var testTable = [['id', 'name'],<br />
 [ 1, 'Programmers' ],<br />
 [ 2, 'WebAdmin' ],<br />
 [ 3, 'Broadband']];<br />
<br />
&lt;hbox&gt;<br />
  &lt;repeater&gt;<br />
    &lt;label value="{name}" /&gt;<br />
  &lt;/repeater&gt;<br />
&lt;/hbox&gt;<br />
<br />
What the 'repeater' control does is remove the repeater node from its parent storing a reference to this 'template' on that control (so we have what was there but none of it is rendered).  Then it loops through the data set adding all of the nodes that were inside of the repeater tags, with their values filled in.  So what gets rendered to the page would be this:<br />
<br />
&lt;hbox&gt;<br />
    &lt;label value="Programmers" /&gt;<br />
    &lt;label value="WebAdmin" /&gt;<br />
    &lt;label value="Broadband" /&gt;<br />
&lt;/hbox&gt;<br />
<br />

The really nice part about this system is that by inserting a repeater node inside of the template, with the outer template filling in the datasource attribute for the inner repeater as it goes, allows you to chain these repeaters to make hierarchical data repeaters.   After I finish polishing everything and test it once more, I am going to port this to use &lt;div repeater="true" &gt; [enter repeated data here]&lt;/div&gt; so that I can achieve the same repeater functionality in standard HTML.   
<br /><br />
Overall this has been my best experience with XBL, most notable because it required only one function block and one line of xbl content binding  ( the &lt;children /&gt; node).  It did however force me to copy code in and out of the xbl document to a standard JS doc to get parse errors to show up (Mozilla was just silently failing when their was a parse error in the XBL Javascript). 
<br /><br />
<a title="Ryan" href="http://blogs.acceleration.net/ryan/">Ryan</a> will probably give us a little preview of his js control scheme based of his interpretations of <a title="xbl alternative" href="http://www.jerf.org/resources/xblinjs/" target="_blank">XBLinJS</a>.  What it seems we've got almost worked out is a simple way to repeat nodes and a simple way to create complex, repeatable, XUL/HTML controls.  Most of this work was inspired by excessive frustration (mostly caused by nonexistant error handling) at the way mozilla handles these two things  and by reading <a href="http://www.jerf.org">Jeremy Bowers</a> site which convinced us to do what we already wanted to do.<br /><br /><br />
UPDATE:<br />
<a href="http://blogs.acceleration.net/russ/articles/1062.aspx">Go Here to see  the Repeater Source</a><br />
<a href="http://blogs.acceleration.net/russ/articles/1145.aspx">Usage Example</a><img src ="http://blogs.acceleration.net/russ/aggbug/819.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Russ</dc:creator><title>XUL Templates Or Javascript Templates</title><link>http://blogs.acceleration.net/russ/archive/2005/04/06/804.aspx</link><pubDate>Wed, 06 Apr 2005 19:41:00 GMT</pubDate><guid>http://blogs.acceleration.net/russ/archive/2005/04/06/804.aspx</guid><description>I've been really frustrated with the XUL template system for a while and have thought about writing a javascript object to handle templating through direct interface with the DOM.  Today I read &lt;a href="http://www.jerf.org/resources/xblinjs/whyNotMozilla/notXulTemplates.html"&gt;XUL Templates are a Waste of Time&lt;/a&gt;.  While Im not completely sure I agree with everything Jeremy Bowers says, reading his rant convinced me it was time to try out writing my own javascript template system.  I broke with standards in this endeavor because one of my biggest complaints about the current template system is the time I spend translating to and from XML-RDF.  I appreciate what RDF is trying to do in a lot of cases and I think that, overall RDF is a great idea.  I hate xml-rdf though.  This is especially true when I need to translate flat SQL selects into RDF just so I can display them in a flat list again.  Toward this end I decided to use the simplest data structure to represent the data for my template system.
&lt;br /&gt;&lt;br /&gt;
&lt;table class="dp-c" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="tools-corner"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;1&lt;/td&gt;&lt;td class="line"&gt;&lt;span&gt;var testTable = [['id', 'name'], &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;2&lt;/td&gt;&lt;td class="line"&gt;              [ 1,  'Programmers' ], &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;3&lt;/td&gt;&lt;td class="line"&gt;              [ 2,  'WebAdmin' ], &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;4&lt;/td&gt;&lt;td class="line"&gt;              [ 3,  'Broadband']]; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;

This  data table gets turned into a data source (this entails creating an object the has columnNames and rows).   Then I just call a function passing in a template ( '&amp;lt;menuitem label="{name}" value="{id}" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" /&amp;gt;'), a data source and a control that I want to add the template nodes to.   This is currently just a prrof of concept that I threw together to figure out the feasibility of this project.  As a side note, for HTML template generation you can just user element.innerHTML += element.template.format(obj).  Also, if the format is throwing you, it accepts an object(hashtable) and replaces keys inside of the '{', '}' with the value from the object passed in.
&lt;br /&gt;&lt;br /&gt;
The places I see for improvement are:
&lt;ul&gt;
&lt;li&gt; Not needing to specify the URI.  I dont know if I can get around this one. &lt;/li&gt;
&lt;li&gt; I need to figure out a way to nest templates.  Currently I haven't even thought about it  yet.&lt;/li&gt;
&lt;li&gt; It would be nice to be able to specify a url to pull the data source from and have that data source refresh dynamically&lt;/li&gt;
&lt;/ul&gt;

&lt;br /&gt;&lt;br /&gt;
&lt;table class="dp-c" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="tools-corner"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;1&lt;/td&gt;&lt;td class="line"&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; JsTemplater = &lt;/span&gt;&lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&lt;span&gt;(){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;2&lt;/td&gt;&lt;td class="line"&gt;    &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;3&lt;/td&gt;&lt;td class="line"&gt;   &lt;span class="keyword"&gt;this&lt;/span&gt;&lt;span&gt;.DataSource = &lt;/span&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&lt;span&gt; ( dataTable ){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;4&lt;/td&gt;&lt;td class="line"&gt;      &lt;span class="keyword"&gt;this&lt;/span&gt;&lt;span&gt;.columnHeaders = dataTable[0]; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;5&lt;/td&gt;&lt;td class="line"&gt;      dataTable.remove(0); &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;6&lt;/td&gt;&lt;td class="line"&gt;      &lt;span class="keyword"&gt;this&lt;/span&gt;&lt;span&gt;.rows = dataTable; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;7&lt;/td&gt;&lt;td class="line"&gt;   }; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;8&lt;/td&gt;&lt;td class="line"&gt;    &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;9&lt;/td&gt;&lt;td class="line"&gt;   &lt;span class="keyword"&gt;this&lt;/span&gt;&lt;span&gt;.DataSource.__doc__ = &lt;/span&gt;&lt;span class="string"&gt;'Constructor for a Template Datasource'&lt;/span&gt;&lt;span&gt;; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;10&lt;/td&gt;&lt;td class="line"&gt;    &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;11&lt;/td&gt;&lt;td class="line"&gt;   &lt;span class="keyword"&gt;this&lt;/span&gt;&lt;span&gt;.attachTemplateToNode = &lt;/span&gt;&lt;span class="keyword"&gt;function&lt;/span&gt;&lt;span&gt;( template, datasource, element ){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;12&lt;/td&gt;&lt;td class="line"&gt;      template = &lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; String(template); &lt;/span&gt;&lt;span class="comment"&gt;//So I can use the format function&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;13&lt;/td&gt;&lt;td class="line"&gt;      element.template = template; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;14&lt;/td&gt;&lt;td class="line"&gt;      element.datasource = datasource; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;15&lt;/td&gt;&lt;td class="line"&gt;      element.bind = &lt;span class="keyword"&gt;function&lt;/span&gt;&lt;span&gt;(){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;16&lt;/td&gt;&lt;td class="line"&gt;         &lt;span class="keyword"&gt;for&lt;/span&gt;&lt;span&gt;( &lt;/span&gt;&lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; row=0 ; row &amp;lt; element.datasource.rows.length ; row++ ){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;17&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; obj = &lt;/span&gt;&lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; Object(); &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;18&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;for&lt;/span&gt;&lt;span&gt;( &lt;/span&gt;&lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; col=0 ; col &amp;lt; element.datasource.columnHeaders.length ;col++){ &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;19&lt;/td&gt;&lt;td class="line"&gt;               obj[element.datasource.columnHeaders[col]] = element.datasource.rows[row][col]; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;20&lt;/td&gt;&lt;td class="line"&gt;               &lt;span class="comment"&gt;//this builds an object for every row whose keys are  the column names and whose values are the... values&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;21&lt;/td&gt;&lt;td class="line"&gt;            } &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;22&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; str = element.template.format(obj); &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;23&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; parser = &lt;/span&gt;&lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; DOMParser(); &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;24&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;var&lt;/span&gt;&lt;span&gt; resultDoc = parser.parseFromString(str, &lt;/span&gt;&lt;span class="string"&gt;'application/xml'&lt;/span&gt;&lt;span&gt;); &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;25&lt;/td&gt;&lt;td class="line"&gt;            &lt;span class="keyword"&gt;if&lt;/span&gt;&lt;span&gt; (resultDoc.documentElement.tagName == &lt;/span&gt;&lt;span class="string"&gt;"parsererror"&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;26&lt;/td&gt;&lt;td class="line"&gt;               &lt;span class="keyword"&gt;throw&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="string"&gt;'there was an error parsing the following template\n\n'&lt;/span&gt;&lt;span&gt;+template; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;27&lt;/td&gt;&lt;td class="line"&gt;&lt;span class="comment"&gt;// hey cool ... templates with error reporting&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;28&lt;/td&gt;&lt;td class="line"&gt;            element.appendChild(resultDoc.documentElement);  &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;29&lt;/td&gt;&lt;td class="line"&gt;         }; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;30&lt;/td&gt;&lt;td class="line"&gt;      };  &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;31&lt;/td&gt;&lt;td class="line"&gt;   }; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="gutter"&gt;32&lt;/td&gt;&lt;td class="line"&gt;})(); &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;img src ="http://blogs.acceleration.net/russ/aggbug/804.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml">I've been really frustrated with the XUL template system for a while and have thought about writing a javascript object to handle templating through direct interface with the DOM.  Today I read <a href="http://www.jerf.org/resources/xblinjs/whyNotMozilla/notXulTemplates.html">XUL Templates are a Waste of Time</a>.  While Im not completely sure I agree with everything Jeremy Bowers says, reading his rant convinced me it was time to try out writing my own javascript template system.  I broke with standards in this endeavor because one of my biggest complaints about the current template system is the time I spend translating to and from XML-RDF.  I appreciate what RDF is trying to do in a lot of cases and I think that, overall RDF is a great idea.  I hate xml-rdf though.  This is especially true when I need to translate flat SQL selects into RDF just so I can display them in a flat list again.  Toward this end I decided to use the simplest data structure to represent the data for my template system.
<br /><br />
<table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tools-corner"></td></tr><tr><td class="gutter">1</td><td class="line"><span>var testTable = [['id', 'name'], </span></td></tr><tr><td class="gutter">2</td><td class="line">              [ 1,  'Programmers' ], </td></tr><tr><td class="gutter">3</td><td class="line">              [ 2,  'WebAdmin' ], </td></tr><tr><td class="gutter">4</td><td class="line">              [ 3,  'Broadband']]; </td></tr></tbody></table>
<br />

This  data table gets turned into a data source (this entails creating an object the has columnNames and rows).   Then I just call a function passing in a template ( '&lt;menuitem label="{name}" value="{id}" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" /&gt;'), a data source and a control that I want to add the template nodes to.   This is currently just a prrof of concept that I threw together to figure out the feasibility of this project.  As a side note, for HTML template generation you can just user element.innerHTML += element.template.format(obj).  Also, if the format is throwing you, it accepts an object(hashtable) and replaces keys inside of the '{', '}' with the value from the object passed in.
<br /><br />
The places I see for improvement are:
<ul>
<li> Not needing to specify the URI.  I dont know if I can get around this one. </li>
<li> I need to figure out a way to nest templates.  Currently I haven't even thought about it  yet.</li>
<li> It would be nice to be able to specify a url to pull the data source from and have that data source refresh dynamically</li>
</ul>

<br /><br />
<table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tools-corner"></td></tr><tr><td class="gutter">1</td><td class="line"><span></span><span class="keyword">var</span><span> JsTemplater = </span><span class="keyword">new</span><span> (</span><span class="keyword">function</span><span>(){ </span></td></tr><tr><td class="gutter">2</td><td class="line">    </td></tr><tr><td class="gutter">3</td><td class="line">   <span class="keyword">this</span><span>.DataSource = </span><span class="keyword">function</span><span> ( dataTable ){ </span></td></tr><tr><td class="gutter">4</td><td class="line">      <span class="keyword">this</span><span>.columnHeaders = dataTable[0]; </span></td></tr><tr><td class="gutter">5</td><td class="line">      dataTable.remove(0); </td></tr><tr><td class="gutter">6</td><td class="line">      <span class="keyword">this</span><span>.rows = dataTable; </span></td></tr><tr><td class="gutter">7</td><td class="line">   }; </td></tr><tr><td class="gutter">8</td><td class="line">    </td></tr><tr><td class="gutter">9</td><td class="line">   <span class="keyword">this</span><span>.DataSource.__doc__ = </span><span class="string">'Constructor for a Template Datasource'</span><span>; </span></td></tr><tr><td class="gutter">10</td><td class="line">    </td></tr><tr><td class="gutter">11</td><td class="line">   <span class="keyword">this</span><span>.attachTemplateToNode = </span><span class="keyword">function</span><span>( template, datasource, element ){ </span></td></tr><tr><td class="gutter">12</td><td class="line">      template = <span class="keyword">new</span><span> String(template); </span><span class="comment">//So I can use the format function</span><span> </span></td></tr><tr><td class="gutter">13</td><td class="line">      element.template = template; </td></tr><tr><td class="gutter">14</td><td class="line">      element.datasource = datasource; </td></tr><tr><td class="gutter">15</td><td class="line">      element.bind = <span class="keyword">function</span><span>(){ </span></td></tr><tr><td class="gutter">16</td><td class="line">         <span class="keyword">for</span><span>( </span><span class="keyword">var</span><span> row=0 ; row &lt; element.datasource.rows.length ; row++ ){ </span></td></tr><tr><td class="gutter">17</td><td class="line">            <span class="keyword">var</span><span> obj = </span><span class="keyword">new</span><span> Object(); </span></td></tr><tr><td class="gutter">18</td><td class="line">            <span class="keyword">for</span><span>( </span><span class="keyword">var</span><span> col=0 ; col &lt; element.datasource.columnHeaders.length ;col++){ </span></td></tr><tr><td class="gutter">19</td><td class="line">               obj[element.datasource.columnHeaders[col]] = element.datasource.rows[row][col]; </td></tr><tr><td class="gutter">20</td><td class="line">               <span class="comment">//this builds an object for every row whose keys are  the column names and whose values are the... values</span><span> </span></td></tr><tr><td class="gutter">21</td><td class="line">            } </td></tr><tr><td class="gutter">22</td><td class="line">            <span class="keyword">var</span><span> str = element.template.format(obj); </span></td></tr><tr><td class="gutter">23</td><td class="line">            <span class="keyword">var</span><span> parser = </span><span class="keyword">new</span><span> DOMParser(); </span></td></tr><tr><td class="gutter">24</td><td class="line">            <span class="keyword">var</span><span> resultDoc = parser.parseFromString(str, </span><span class="string">'application/xml'</span><span>); </span></td></tr><tr><td class="gutter">25</td><td class="line">            <span class="keyword">if</span><span> (resultDoc.documentElement.tagName == </span><span class="string">"parsererror"</span><span>) </span></td></tr><tr><td class="gutter">26</td><td class="line">               <span class="keyword">throw</span><span> </span><span class="string">'there was an error parsing the following template\n\n'</span><span>+template; </span></td></tr><tr><td class="gutter">27</td><td class="line"><span class="comment">// hey cool ... templates with error reporting</span><span> </span></td></tr><tr><td class="gutter">28</td><td class="line">            element.appendChild(resultDoc.documentElement);  </td></tr><tr><td class="gutter">29</td><td class="line">         }; </td></tr><tr><td class="gutter">30</td><td class="line">      };  </td></tr><tr><td class="gutter">31</td><td class="line">   }; </td></tr><tr><td class="gutter">32</td><td class="line">})(); </td></tr></tbody></table><img src ="http://blogs.acceleration.net/russ/aggbug/804.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Russ</dc:creator><title>More Dynamic XUL Template Stuff</title><link>http://blogs.acceleration.net/russ/archive/2005/02/08/629.aspx</link><pubDate>Tue, 08 Feb 2005 16:08:00 GMT</pubDate><guid>http://blogs.acceleration.net/russ/archive/2005/02/08/629.aspx</guid><description>&lt;a href="http://www.mozilla.org/docs/ora-oss2000/chatzilla/xultemplates-example2.html"&gt;This page on Mozilla.org&lt;/a&gt; has the info I needed when I was previously using templates and explains (doesnt justify) the &lt;a href="http://blogs.acceleration.net/Russ/archive/2005/01/17/508.aspx"&gt;datasources attribute problems I ran up against.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
The way we have been working with XUL data lists has mostly been through the Tree widgets.  &lt;a href="http://docs.mandragor.org/files/Misc/Mozilla_applications_en/mozilla-chp-9.html"&gt;This site&lt;/a&gt; seems to have a pretty good overview of xul templates (with source (thanks planet XUL for being the most useful useless site on the net)), and they suggest using the listbox for most common chores instead of the full tree control.&lt;img src ="http://blogs.acceleration.net/russ/aggbug/629.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><a href="http://www.mozilla.org/docs/ora-oss2000/chatzilla/xultemplates-example2.html">This page on Mozilla.org</a> has the info I needed when I was previously using templates and explains (doesnt justify) the <a href="http://blogs.acceleration.net/Russ/archive/2005/01/17/508.aspx">datasources attribute problems I ran up against.</a><br /><br />
The way we have been working with XUL data lists has mostly been through the Tree widgets.  <a href="http://docs.mandragor.org/files/Misc/Mozilla_applications_en/mozilla-chp-9.html">This site</a> seems to have a pretty good overview of xul templates (with source (thanks planet XUL for being the most useful useless site on the net)), and they suggest using the listbox for most common chores instead of the full tree control.<img src ="http://blogs.acceleration.net/russ/aggbug/629.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Russ</dc:creator><title>Dynamic XUL Template Datasources.</title><link>http://blogs.acceleration.net/russ/archive/2005/01/17/508.aspx</link><pubDate>Mon, 17 Jan 2005 16:35:00 GMT</pubDate><guid>http://blogs.acceleration.net/russ/archive/2005/01/17/508.aspx</guid><description>To take advantage of XUL templates you want something like:&lt;br /&gt;
&lt;code&gt;&lt;pre&gt;
&amp;lt;vbox id="boxPlanAttributeValues" datasources="SomeURL" ref="SomeURIforTheData "&amp;gt;
      &amp;lt;template&amp;gt;
          &amp;lt;hbox uri="rdf:*" attributevalueid="rdf:SomeUril#Id"&amp;gt;  
                &amp;lt;label value="rdf:SomeUril#Attribute" /&amp;gt;
                &amp;lt;label value="rdf:SomeUril#Value" /&amp;gt;
                &amp;lt;hbox align="right" flex="1"&amp;gt;
                    &amp;lt;button maxwidth="30px" label="X" oncommand="" /&amp;gt;
                &amp;lt;/hbox&amp;gt;
          &amp;lt;/hbox&amp;gt;
      &amp;lt;/template&amp;gt;
 &amp;lt;/vbox&amp;gt;
&lt;/pre&gt;&lt;/code&gt;
&lt;br /&gt;
To make this dynamic, (for example change a where clause so that it is bound differently):we should only need to remove the data source and ref from the above xml and use this bit of javascript:&lt;br /&gt;
&lt;code&gt;&lt;pre&gt;
this.boxPlanAttributeValues.setAttribute("ref", "SomeURIforTheData " );
this.boxPlanAttributeValues.setAttribute("datasources", SomeURL );
this.boxPlanAttributeValues.builder.refresh();
&lt;/pre&gt;&lt;/code&gt;
The problem I was having was that this.boxPlanAttributeValues.builder is null.  The solution, after banging my head against the wall for hours, was to make sure that the xul tag still has [ datasources="" ref="" ] in it.  &lt;br /&gt;&lt;br /&gt;This is the problem with software... it all sucks.&lt;img src ="http://blogs.acceleration.net/russ/aggbug/508.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml">To take advantage of XUL templates you want something like:<br />
<code><pre>
&lt;vbox id="boxPlanAttributeValues" datasources="SomeURL" ref="SomeURIforTheData "&gt;
      &lt;template&gt;
          &lt;hbox uri="rdf:*" attributevalueid="rdf:SomeUril#Id"&gt;  
                &lt;label value="rdf:SomeUril#Attribute" /&gt;
                &lt;label value="rdf:SomeUril#Value" /&gt;
                &lt;hbox align="right" flex="1"&gt;
                    &lt;button maxwidth="30px" label="X" oncommand="" /&gt;
                &lt;/hbox&gt;
          &lt;/hbox&gt;
      &lt;/template&gt;
 &lt;/vbox&gt;
</pre></code>
<br />
To make this dynamic, (for example change a where clause so that it is bound differently):we should only need to remove the data source and ref from the above xml and use this bit of javascript:<br />
<code><pre>
this.boxPlanAttributeValues.setAttribute("ref", "SomeURIforTheData " );
this.boxPlanAttributeValues.setAttribute("datasources", SomeURL );
this.boxPlanAttributeValues.builder.refresh();
</pre></code>
The problem I was having was that this.boxPlanAttributeValues.builder is null.  The solution, after banging my head against the wall for hours, was to make sure that the xul tag still has [ datasources="" ref="" ] in it.  <br /><br />This is the problem with software... it all sucks.<img src ="http://blogs.acceleration.net/russ/aggbug/508.aspx" width = "1" height = "1" /></body></item></channel></rss>