XUL:Xul Templates: Difference between revisions

 
Line 346: Line 346:
=== Comments Sean McMurray ===
=== Comments Sean McMurray ===


I have a small xbl that is fairly rough, but allows to me use inline xsl templates.
I have written an XBL to do inline XSL templates.
It is less than 100 lines of xbl.
The XBL has two bindings: one for datasources, one for templates.


Right now it works against xml datasources. The datasource query can be affected by content outside the template.
     <xslTemplate datasource="list;including;myDS">
 
I think it could be modified to work with RDF, or to be extensible. But it would take more talent than I have.
 
My XBL has two binding: one for datasources, one for templates.
 
 
'''Templates'''
 
You place a template in your document like this:
     <myTemplate style="-moz-binding: url('myTemplateIdea.xbl#xslTemplate');" datasource="list;of;datasources">
         <xsl:stylesheet ...../>
         <xsl:stylesheet ...../>
     </myTemplate>
     </xslTemplate>
 
Templates can be bound to one or more datasources. The datasources must be defined elsewhere within the document.
 
 
'''Datasources'''
 
You place an datasource in your document like this:
    <myElement id="myDS" href="uri://to/a/datasource" style="-moz-binding: url('myTemplateIdea.xbl#datasource');"/>
 
The href attribute points to the location of the data. This href is used to post an XMLHttpRequest. Datasources can also have a "request" attribute, the contents of which are included in the HTTP Post. Datasource elements can also contain js code that is invoked before the HTTP Post. This is useful for manipulating the href or request attributes. For example:
    <myElement id="myDS" ...>
        <![CDATA[
            if(document.getElementById("someotherelement").value=="Just what I want")
                this.request="someparam=whateverIwant";
        ]]>
    </myElement>
 
The datasource also acts as a cache. It stores the response to the HTTP Post in an xbl property. Whenever that property is changed, all templates bound to the datasource are re-transformed.


    <xmlDataSource id="myDS" href="uri://to/a/datasource" />


I think that my crude little XBL could be made to work for RDF, SOAP, XMLRPC, or whatever. You could have a different XBL for each type of datasource. And with work from the geniuses around here, it could be cleaned up a lot.
For more, please see [[XUL Talk:Xul Templates]]
6

edits