XUL:Templates with XML: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
Line 1: Line 1:
Templates will also allow generating content from XML sources as well as RDF. To use an XML source set the querytype attribute on the root element to 'xml', as in the following example:
Templates will allow generating content from XML sources as well as RDF. To use an XML source set the querytype attribute on the root element to 'xml', as in the following example:


   <vbox id="list" datasources="xml-url" ref="." querytype="xml">
   <vbox id="list" datasources="xml-url" ref="." querytype="xml">
Line 66: Line 66:
   </action>
   </action>


In this example, the ?number variable is bound to the result of the 'position()' XPath expression. However, the ?name variable is not bound to a value, so it is used to retrieve the name attribute instead.
In this example, the ?number variable is bound to the result of the 'position()' XPath expression. However, the ?name variable is not bound to a value, so it is used to retrieve the name attribute instead. Note that the context for the expression in an assign element is each result, whereas the context for the expr expression on the query is the root of the XML source document.


This technique works similar to how the &lt;binding&gt; element is used, however the &lt;assign&gt; element requires a value to be set in order to generate a result. In the above example, the expression 'position()' will always return a value, but if it didn't, no output would be generated for that result. As with RDF templates, the &lt;binding&gt; element may be used for optional value.
This technique works similar to how the &lt;binding&gt; element is used, however the &lt;assign&gt; element requires a value to be set in order to generate a result. In the above example, the expression 'position()' will always return a value, but if it didn't, no output would be generated for that result. As with RDF templates, the &lt;binding&gt; element may be used for optional value.
XML templates also support recursion in the same way as RDF templates. The result of each iteration will be used as the context for the next iteration.
287

edits

Navigation menu