40
edits
Changes
→xul templates
For more, please see [[XUL:Xul XSLT Templates]]
=== Comments Conor Dowling ===
A lot of XUL templates were used to build the "factlog" of a new history web site, http://www.the325project.org. They are powerful and work though like everything else they can be improved.
There are 30 or so templates in http://www.the325project.org/factlog/325FactlogBody.xul (it takes a minute to load - look at the source). There are three types:
# simple literal value extraction ex/ the name of a person
# one level of indirection: get a literal from a referenced resource ex/ name of person married to another person
# resources that reference a resource of interest ex/ name of events that a given person took part in
Mozilla RDF shows its age (doesn't support xml:base so no ID's) and Mozilla templates seem to believe that everything begins and ends in lists. So we clearly distinguished between our core RDF and the RDF that Mozilla would process.
First off, we synthesized a list of all the RDF resources of the system and ID's set in the context of a base were transformed into abouts.
Literal value extraction also needs Mozilla specific RDF. We didn't see a way to get a literal directly from a resource. For example, this won't work:
<pre>
<content uri="?uri"/>
<triple subject="?uri"
predicate="http://www.the325project.com/elements/0.1#name"
object="?name"/>
</pre>
However, massage a blank node into your RDF to hold the literal value and hey presto:
<pre>
<content uri="?uri"/>
<triple subject="?uri"
predicate="http://www.the325project.com/elements/0.1#bn_name"
object="?bn_name"/>
<triple subject="?bn_name"
predicate="http://www.the325project.com/elements/0.1#value"
object="?name"/>
</pre>
Some level of dynamic templating is supported in Mozilla now. For example, a type selector in the factlog interface allows you to pick the type of resource its tree displays. This uses a "trick" to set the value of a "settable filter" triple.
<pre>
<triple settableTriple="true" subject="?resource"
predicate="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
object="?dummyvariable"/>
</pre>
A small piece of javascript gets this triple and sets the value of "dummyvariable" to the type you want. It then refreshes the tree.
In the interface, each resource type (person, place etc) has its own xul which calls out to per-resource templates. For example, most resources have a "name" field and so their XUL needs to display a name. They all share a "namesPropertyTemplate".
<pre>
<row datasources="t3pm_people.rdf t3pm_places.rdf t3pm_events.rdf t3pm_generatedLists.rdf" ref="rdf:null" template="namesPropertyTemplate"/>
...
<template id="namesPropertyTemplate">
<rule>
<conditions>
...
</pre>
The shortcoming that you can't extract the "about" or "type" values for resources needs a workaround. Basically, these values are duplicated in application specific fields. Here's how a label becomes a link. Start with the right attributes and then add XBL to make it into a link.
<pre>
<label uri="?text" t3p:about="?t3pabout" t3p:type="http://www.the325project.com/elements/0.1#Text" value="?name"/>
</pre>
A few simple changes would make the current templating system much easier to use:
# being able to wildcard and select all the literals asserted about a resource. Why explicitly call out each?
# being able to extract a literal directly - no need for the blank node workaround
# being able to extract the about and type of a resource
Now this is the first pass at this "factlog". In time, we won't be able to load all the RDF needed in one go and some of the incremental loading mentioned above will be necessary. For now though, the templates work. Our greatest concern was that there is no event to tell when RDF loading is complete (hence the hokey script used in the opening splash screen) and that loading seems to block the browser. Make RDF loading asynchronous and give us an "RDF Loaded" event and we can live with the templates for now. Of course, that's just this site.