mozilla
Your Search Results

    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="http://www.xulplanet.com/rdf/myneighbourhood">
        <r:people>
          <rdf:Seq>
            <rdf:li rdf:resource="http://www.xulplanet.com/rdf/person/1"/>
            <rdf:li rdf:resource="http://www.xulplanet.com/rdf/person/2"/>
          </rdf:Seq>
        </r:people>
      </rdf:Description>
    
      <rdf:Description rdf:about="http://www.xulplanet.com/rdf/person/1"
                       dc:title="Nathan"/>
    
      <rdf:Description rdf:about="http://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="http://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="http://www.xulplanet.com/rdf/people" object="?people"/>
          <member container="?people" child="?item"/>
        </query>
        <rule>
          <binding subject="?item" predicate="http://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,