Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Using Multiple Queries to Generate More Results

Combining Results Together

One interesting technique is to use several queries to combine two sets of unrelated data together. To do this, we create one query to generate one set of results and a second query to generate another set of results. If a result from the second query wasn't also matched by the first query, it will have content created for it. Recall that when the member resource for a query matches several rules, only the earliest query that matches will have content generated for it. If resources don't overlap, we can generate content for two different parts of the RDF data.

If we add the following data about people to the neighbourhood datasource:

  <rdf:Description rdf:about="https://www.xulplanet.com/rdf/myneighbourhood">
    <r:people>
      <rdf:Seq>
        <rdf:li rdf:resource="https://www.xulplanet.com/rdf/person/1"/>
        <rdf:li rdf:resource="https://www.xulplanet.com/rdf/person/2"/>
      </rdf:Seq>
    </r:people>
  </rdf:Description>

  <rdf:Description rdf:about="https://www.xulplanet.com/rdf/person/1"
                   dc:title="Nathan"/>

  <rdf:Description rdf:about="https://www.xulplanet.com/rdf/person/2"
                   dc:title="Karen"/>

We can then use two queries to generate results from different parts of the datasource. The first query will match the streets as before, but the second query will generate a result for each person. A header class is used to distinguish the content, although you could use exactly the same content if you wish.

<template>
  <queryset>
    <query>
      <content uri="?start"/>
      <member container="?start" child="?item"/>
    </query>
    <rule>
      <binding subject="?item" predicate="https://purl.org/dc/elements/1.1/title" object="?title"/>
      <action>
        <label uri="?item" value="?title" class="header"/>
      </action>
    </rule>
  </queryset>
  <queryset>
    <query>
      <content uri="?start"/>
      <triple subject="?start" predicate="https://www.xulplanet.com/rdf/people" object="?people"/>
      <member container="?people" child="?item"/>
    </query>
    <rule>
      <binding subject="?item" predicate="https://purl.org/dc/elements/1.1/title" object="?title"/>
      <action>
        <label uri="?item" value="?title"/>
      </action>
    </rule>
  </queryset>
</template>

You can view the example.

Multiple Queries with XML Sources

You can also use more than query when using an XML source. Here is an example which generates two sets of results and shows them together.

<vbox datasources="people.xml" ref="*" querytype="xml">
  <template>
    <queryset>
      <query expr="group[@name='Male']/*"/>
      <action>
        <checkbox uri="?" label="?name"/>
      </action>
    </queryset>
    <queryset>
      <query expr="group[@name='Female']/*"/>
      <action>
        <label uri="?" value="?name"/>
      </action>
    </queryset>
  </template>
</vbox>

Document Tags and Contributors

 Contributors to this page: Sheppy, Enn
 Last updated by: Sheppy,