Query Styling
Overview
By default, query results are rendered as a table. It is however possible to customize the styling of the query results. This is done by supplying a style_hint option in the query, for example:
select name where true option style_hint = 'bullets'
The style hint 'bullets' is included as a sample with Daisy, it styles the results as a bulleted list, taking the first selected value (here 'name') as the text to put next to the bullet.
Implementing query styles
Style hints are implemented using XSL. Implementing a style hint is a matter of adding a template to the query-styling-(html|xslfo).xsl files of a skin.
If you want the query styles to be available to all skins, it is recommended to add them to the query-styling-*.xsl of the default skin. Otherwise, add them to the skin of your choice.
The stylesheets for the query styling are located in the following directory:
<wikidata directory>/resources/skins/<skin-name>/query-styling
Thus for the default skin, this is:
<wikidata directory>/resources/skins/default/query-styling
If this directory would not yet exist in your wikidata directory, you can simply create it.
Then in that directory, create a file called query-styling-html.xsl (if it doesn't exist already). The following shows an example of what the XSL could look like.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://outerx.org/daisy/1.0">
<xsl:include href="daisyskin:/(default)(webapp)query-styling/query-styling-html.xsl"/>
<xsl:template match="d:searchResult[@styleHint='enum']">
<ol>
<xsl:for-each select="d:rows/d:row">
<li>
<a href="{$searchResultBasePath}{@documentId}.html?branch={@branchId}&language={@languageId}">
<xsl:value-of select="d:value[1]"/>
</a>
</li>
</xsl:for-each>
</ol>
</xsl:template>
<!-- Add other query-styling templates here -->
</xsl:stylesheet>
Here we implemented the query styling for the style hint "enum". It is basically the same as the bullets styling, but using an <ol> instead of <ul>.
Also note the special xsl:include. By creating this query-styling-html.xsl file for the default skin, we hide the one in the default skin in the webapp directory. However, we can import it in the current XSL using this instruction. The "(default)" in the href indicates the name of the skin (if not specified, the 'current skin' is used), and the "(webapp)" tells to explicitely use the file from the webapp directory, not the one from the wikidata directory (which would be the file we have created here, so if we didn't add the (webapp) we would have a recursive include).
Usually when an XSLT or one of the XSLTs included/imported by it changes, Cocoon should reload it. However, it seems this only works for the first level of includes, if included files themselve again include other XSLTs, it seems to stop working. Therefore changes to the file query-styling-html.xsl are not immediately reflected in the wiki. There is an easy work-around to avoid having to restart the wiki In order to let the changes take effect: simply touch an XSLT which Cocoon will check for changes, in this case the searchresult.xsl (which is a first-level include in document-to-html.xsl). In case you applied document type specific styling, you have to touch the stylesheet you created for that purpose (e.g. <wikidata directory>/resources/skins/default/document-styling/html/mydoctype.xsl). ('Touching' means updating the last modification time of the file, e.g. by saving it in an editor, or on unix using the touch command).
If you would add a query-styling-html.xsl to another skin than the default skin, and would like to include the stylings from the default skin, you can use the following include instruction in the XSL:
<xsl:include href="daisyskin:/(default)query-styling/query-styling-html.xsl"/>
Note that the href doesn't contain the "(webapp)" part, so that the daisyskin source will first check for a query-styling-html.xsl for the default skin in the wikidata directory.
For more information on the daisyskin source, see its documentation.



There are no comments.