XUL:Templates with XML: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
 
No edit summary
Line 32: Line 32:
     </template>
     </template>
   </vbox>
   </vbox>
Multiple rules and conditions may also be used as with RDF templates.
  <vbox datasources="xml-url" ref="." querytype="xml" flex="1">
    <template>
      <query expr="person[position()>1]">
      <rule>
        <where subject="?name" rel="equals" value="Samantha"/>
        <action>
          <button uri="?" label="?name is a female."/>
        </action>
      </rule>
      <rule>
        <action>
          <button uri="?" label="?name is a male."/>
        </action>
      </rule>
    </template>
  </vbox>
This example shows the full syntax for XML templates, where the expr attribute is used on the &lt;query&gt; element.
The assign element allows the assignment of additional values to variables, in case you want the values to be calculated. If a variable is referred to that does not have an assignment, it is assumed to refer to the name of an attribute. This latter case is used in the earlier examples.
  <query expr="person">
    <assign var="?number" expr="position()"/>
  </query>
  <action>
    <hbox uri="?">
      <label value="?number"/>
      <button value="?name"/>
    </hbox>
  </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.
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.
287

edits

Navigation menu