We can add more triples to the previous example to show more information. For example, a description could be added to a photo. To do this all we need to do is add the necessary data to the RDF datasource and add another <triple> element to the template's conditions.
<conditions> <content uri="?start"/> <member container="?start" child="?photo"/> <triple subject="?photo" predicate="http://purl.org/dc/elements/1.1/title" object="?title"/> <triple subject="?photo" predicate="http://purl.org/dc/elements/1.1/description" object="?description"/> </conditions>
It works similarly to the previous triple. The ?photo variable is filled in with the known value and then the arc is looked up in the datasource, filling in the value for the ?description variable. The ?description variable would then be used in the action body. Let assume though, that we are only going to add a description to one of the photos in the datasource; the other two photos will not have a description. This may mean the description is not known, or that it wasn't filled in by the user.
<rdf:Description rdf:about="http://www.xulplanet.com/ndeakin/images/t/palace.jpg" dc:title="Palace from Above" dc:description="View from the top of the tower looking east of the Doges Palace"/>
If you try a full example based on this data, you will notice that only one result has been generated. This is because only one item has a description. Here is the data after the first <triple> has been evaluated, but before the description triple has been examined:
(?start = http://www.xulplanet.com/rdf/myphotos, ?photo = http://www.xulplanet.com/ndeakin/images/t/palace.jpg, ?title = 'Palace from Above') (?start = http://www.xulplanet.com/rdf/myphotos, ?photo = http://www.xulplanet.com/ndeakin/images/t/canal.jpg, ?title = 'Canal') (?start = http://www.xulplanet.com/rdf/myphotos, ?photo = http://www.xulplanet.com/ndeakin/images/t/obelisk.jpg, ?title = 'Obelisk')
The second triple will add a ?description for the first photo, adding a fourth variable-value pair to the existing data. However, when the builder doesn't find any value for a condition, the entire potential result is removed. For the second photo, the datasource doesn't have any matches for the description, so that potential result will be removed. The same happens for the third photo. In the end, only one photo remains.
(?start = http://www.xulplanet.com/rdf/myphotos, ?photo = http://www.xulplanet.com/ndeakin/images/t/palace.jpg, ?title = 'Palace from Above', ?description = 'View from the top of the tower looking east of the Doges Palace')
Thus, only one match exists, so only one set of content is generated.
Sometimes, it would be useful to have triples that match conditionally, that is , have a triple that doesn't cause a result to be removed as a possible match. This is done with a <binding> element. This tag doesn't go in the <conditions> block but instead inside a <bindings> element. The syntax is as follows:
<rule> <conditions> ... </conditions> <bindings> <binding subject="?photo" predicate="http://purl.org/dc/elements/1.1/description" object="?description"/> </bindings> </rule>
The description triple has been changed to a <binding> element, but the attributes are the same. This allows a match to occur even if the description is not specified in the data. The template builder examines bindings after all the conditions have been applied. It has already determined, in this example, that three matches have been found. The builder continues by filling in the values for any bindings. They are evaluated in a similar although simpler mannner as the triples. The value of the ?photo variable is known for each match, the datasource is examined for the description, and the value of the ?description variable is filled in. The effect is three matches, only one of which will display a description. The photos that don't have a description will be treated as if the description was blank. That is, the ?description variable will be replaced with an empty string when analyzing the attributes in the action body.
Here is this example.
You can have more than one binding if you wish. The others will be evaluated in a similar way. For instance, the title triple could be moved to a binding such that it could be optional also.