This section describes the more advanced rule syntax.
The Full Rule Syntax
The rule syntax described so far is useful for some datasources but sometimes you will need to display data in more complicated ways. The simple rule syntax is really just a shortcut for the full rule syntax which is described below. Like the simple rules, full rules are placed within the ref_rulerule tag.
Full rules contain three child tags, a ref_conditionsconditions tag, a ref_bindingsbindings tag and an ref_actionaction tag, although the ref_bindingsbindings tag is not always needed.
The ref_conditionsconditions element is used to specify the criteria for matching a given resource. You can specify a number of conditions, all of which must match. In the simple rule syntax, the conditions are placed directly on the ref_rulerule element itself.
If the conditions match for a resource, the content placed within the ref_actionsactions tag is generated. In the simple syntax, the content is placed directly inside the ref_rulerule.
Rule Conditions
When a tree, menu or other element with a datasource generates content, the template builder first finds the resource referred to by the ref attribute. It then iterates over all that resource's child resources. It applies each resource to the conditions. If the conditions match for that resource, the content in the ref_actionsactions element is generated for that resource. If the conditions do not match, no content is generated.
The ref_conditionsconditions element can contain three elements. The first is the ref_contentcontent element, which should always exist once and only once. It serves as a placeholder as the template builder iterates through the resources. It specifies the name of a variable in which is placed a reference to the root resource while the conditions are analyzed for a match. The root resource is the one specified by the ref attribute on the element containing the template.
The syntax of the ref_contentcontent element is as follows:
The question mark indicates that the text following it is a variable. You can then use the variable 'var' within the remainder of the conditions. Of course, you can name the variable whatever you want.
The next element is the ref_membermember element, which is used to iterate through a set of child resources. In RDF terms, that means a container such a Seq, Bag or Alt. Let's say you have a list of cities described in the following RDF/XML fragment:
You want to display a row in a tree for each city. To do this, use the ref_membermember element as in the following:
The template builder starts by grabbing the value of the ref attribute, which in this case is rdf/weather/cities. This resource will be placed in the 'list' variable as specified by the ref_contentcontent tag. We can then get related resources to the root resource by using the 'list' variable.
The template builder then sees the ref_membermember element. It causes the builder to iterate over the children of an element. The parent is specified by the container attribute and the children are specified by the child attribute. In the example above, the value of the container attribute is the variable 'list'. Thus the parent will be the value of the list variable, which has been set to the root resource 'rdf/weather/cities'. The effect will be to iterate through the list of children of 'rdf/weather/cities'.
If you look at the RDF above, the 'rdf/weather/cities' resource has four children, one for each different city. The template builder iterates through each one, matching the child against the value of the child attribute. In this case, it is just set to the variable 'city'. So the builder will set the 'city' variable to the each child resource in turn.
Because there are no more conditions, the condition matches for each of those four resources and the builder will generate content for each of the four. Of course, the example above doesn't have any content. We'll add that later.
The next element is the ref_tripletriple element. It is used to check for the existence of a given triple (or assertion) in the RDF datasource. A triple is like a property of a resource. For example, a triple exists between a bookmark and its URL. This might be expressed as follows:
A Bookmark to -> URL -> www.
This means that there is a triple between the bookmark 'A Bookmark to ' and 'www.' by the URL property. The first part of this expression is called the subject, the second part is called the predicate and the last part is called the object. As a ref_tripletriple element, it would be expressed as follows:
This has been simplified a bit from the real thing. The predicate would normally include the namespace, and the subject would be the bookmark's resource id, not the bookmark's title as used here. In fact, the bookmark's title would be another triple in the datasource using the Name predicate.
You can replace the subject and object on the ref_tripletriple element with variable references, in which case values will be substituted for the variables. If no value is defined for a variable yet, the template builder will look up the value in the datasource and assign it to the variable.
Let's say we wanted to add a weather prediction to the city datasource. The following conditions might be used:
The template builder will iterate over each city as before. When it gets to the triple, it will look for an assertion in the RDF datasource for a city's weather prediction. The variable 'pred' will be assigned the prediction. The builder will repeat this for each of the four cities. A match occurs and the builder will generate content for each city that has a prediction. If the city has no prediction resource, the condition does not match and no content will be generated for that city. Note that you do not need to put 'rdf:' at the beginning of the predicate, as that part is assumed.
We could also replace the object with an in-line value. For example:
This example is similar but we specify that we want to match on 'Cloudy'. The result is that the conditions will only match for cities where the prediction is 'Cloudy'.
We can add more triples to require more matches. For example, in the example above, we might want to check for the temperature and the wind speed. To do this just add another triple which checks for the additional resource. The condition will match if all of the triples provide values.
The example below will check for an extra triple for the name of the city. It will be assigned to the 'name' variable. The condition will only match if the city has both a name and a prediction.
Generating Content
The content to generate for a rule is specified inside the ref_actionaction element. This should be the content for the rows of the tree, menu items, or whatever content you want to generate. Within the content, you can refer to variables that were defined in the conditions. Thus, in the weather example above, you could use the variables 'name' or 'pred' to display the city or prediction. You can use the 'list' or 'city' variables also, but they hold resources, not text, so they won't likely have meaningful values to users.
In the simple rule syntax, you use the syntax uri='rdf:*' to indicate where content should be generated. In the full syntax, you set the value of the uri attribute to a variable which you used in the conditions. Usually, this will be the variable assigned in the child attribute of the ref_membermember element.
The following example shows a complete tree with conditions and an action. You can view the RDF file separately. "weather.txtSource "weather.rdfRDF
Example 6.9.1: /ex_6_9_1.xul.txt'>Source
Bhopal news
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100