Pre-renderers

Introduction

  1. Overview
  2. Example

Tags description

  1. title
  2. field
  3. row
  4. column

Introduction

Overview

The pre-renderers section convert your data view to a 2D array representation, in order to adapt it to 2D-based rendering format (e.g. CSV, chart, HTML table...). Configuring this section is optional, but it allows for complete control on 2D-renderings. Moreover, it may improve performance if a lot of data is rendered, because the code generated from this section will always be simpler than the code of the default pre-rendering behavior (which is designed to support any XML format).

You will find below a complete example browsing most of the possibilities of this section. Copy-paste this view configuration in your etc/app/views/*.xml file and check the result : /lavoisier/rowcol

Notice: You can also generate the rowcol format using an XSL file. You just have to set attribute @row-column of the pre-renderer tag with the location of your stylesheet. Please find an example here.


Example
The file 'languages.xml' contains the following data:
<root date="January 2013">
    <language slug="C_(programming_language)" rate="6.1%">C++</language>
    <language slug="C_(programming_language)" rate="17.8%">C</language>
    <language slug="Objective-C" rate="9.1%">Objective-C</language>
    <language slug="C_Sharp_(programming_language)" rate="5.5%">C#</language>
    <language slug="Java_(programming_language)" rate="17.4%">Java</language>
</root>
The pre-renderers configuration is as follow:
        <pre-renderers>
            <title>concat("Programming Language - TOP ", count(/root/language))</title>
            <field label="source" link="http://www.tiobe.com">concat("TIOBE ",/root/@date)</field>
            <row foreach="root/language">
                <column label="Position">position()</column>
                <column label="Programming Language" link="http://en.wikipedia.org/wiki/{@slug}">text()</column>
                <column label="Ratings" order="descending" unit="%">substring-before(@rate, "%")</column>
            </row>
        </pre-renderers>

Tags description

title
title allows you to set a "h1" html header. Only a single occurrence is allowed as a very first child of <rendering>. The element value must be a xpath.
<title>concat("Programming Language - TOP ", count(/root/language))</title>

field
Use tag <field> just after <title> tag to set one of several key/value pair. @label and @link attributes are optional. If a label is not provided, a default label value will be automatically deduced from the node name. The value of this element must be a valid xpath, so don't forget to use quotes to encapsulate a single string.
<field label="source" link="http://www.tiobe.com">concat("TIOBE ",/root/@date)</field>

row
It allows you to build an array defining several <column> as children element and a set of rows setting the @foreach attribute with an xpath expression. The following example defines a loop for each element <language>:
<row foreach="root/language"></row>

column
Now you can define inside <row> a list of <column>. Content of cells is defined setting the value of this element which is requiring xpath expression. @label, @link, @hidden, @order and @number attributes are optional.

Examples:
  • You can define a @label attribute to set the column header :
    <column label="Position">position()</column>
  • Using @link attribute, you are able to attach a link on a cell value. Xpath result encapsulated inside braces, {} can be easily mixed to static text.
    <column label="Programming Language" link="http://en.wikipedia.org/wiki/{@slug}">text()</column>
  • Finally, add a descending numeric sort using @order and @unit optional attributes. If you don't use @unit, sort will be a 'text' sort. @unit is used too, in chart display.
    <column label="Ratings" order="descending" unit="%">substring-before(@rate, "%")</column>