19. Advanced functionalities

This section will describe how the designer generates the XSL-FO code and how you can add your own code. Note this section requires some basic knowledge of XSLT and XPATH.

Understanding the generated code for areas

Each detail area (see 1 in the screenshot) in the designer will be printed as a table:

In the order.xre example we can see the described structure for the order lines:

The result is:
Note the code generated for the report header is similar but slightly different in the locations.

Introduction to Variables and Keys


This section will introduce the use of XSLT Variables and Key in the designer.

Variables can be defined like this:

<xsl:variable name="Variablename" select="value"/>

Some examples are:

The variable can later on be read using the syntax $variable name. For example:

Keys are similar to database lookups. First you need to defined a key (this has to be done in the initialization part of the report). The syntax is:

<xsl:key name="keyname" match="node" use="indexexpression"/>


The Lookup can be the executed using the key() function:

    key(keyname,expression)

The expression can be a constant like 'Peter' , a variable or a node (XPath)


For this input data:

<Persons>
    <Person>
        <FirstName>Peter</FirstName>
        <LastName>Smith</LastName>
    </Person>
    <Person>
        <FirstName>David</FirstName>
        <LastName>Brown</LastName>
    </Person>
    <Person>
        <FirstName>James</FirstName>
        <LastName>Davis</LastName>
    </Person>
    <Person>
        <FirstName>Peter</FirstName>
        <LastName>Jones</LastName>
    </Person>
</Persons>

The key function can be used in the report like this:

Tip! You can leave the XML Node of the area empty and instead you can use the Advanced fields (see next section) to create a custom loop for the area as below:





We deliver an example named PersonKey.xre where you can see the implementation  of this section. Please note there are other ways of achieving  the same result without using variables or keys. The only purpose of this example is to show these features in action.

Adding your own code


There are several way of adding XSL-FO code to your report:

Markers (variable data in page header and footer)


Markers are used in XSL:FO to keep track of the values in the pages as they are being rendered. The main purpose of the markers is to be used in Page Headers and Page Footer. By using markers you can have variable data in the page header and footers which otherwise can only contain constant data.

The delivered example tasksMarkers shows how to use the markers.


The following screenshot shows the output of one of the page footer fields, the last value in the page has been added to the page footer, while the barcode shows the first name in the page




Note: if you need to define more than 2 markers the code below can be used in the "After row code" field

for report headers use:

<fo:block>
<fo:marker marker-class-name="markerName">   
<xsl:value-of select="yourXPATH"/>            
</fo:marker>
</fo:block>

for details areas use:

<fo:table-row  max-height="0mm"  height="0mm" border-collapse="separate" border-style="none">
<fo:table-cell  border-style="none">
<fo:block>
<fo:marker marker-class-name="markerName">   
<xsl:value-of select="yourXPATH"/>           
</fo:marker>
</fo:block>
</fo:table-cell>
</fo:table-row>


Advanced examples


The following examples show how to use some of the advanced features:


Using third party XSLT templates

You can use third party XSLT template files to extend the functionality of the designer. One example is this library:

https://sourceforge.net/projects/xsltsl/


In the library you will find functions to, for example, format date/time date or string values.

The example tasks_xsl.xre shows how to use this feature. The steps are:

  1. extract one of the templates from the library. This is required to keep the report size small (do not use the original "large" files).

    For example this snippet would convert a day number to the name of the day in english (make sure you have namespace and prefix, see red texts):

    <xsl:template name="dt:get-day-of-the-week-name" xmlns:dt="http://xsltsl.org/date-time">
      <xsl:param name="day-of-the-week"/>
       <xsl:choose>
        <xsl:when test="$day-of-the-week = 0">Sunday</xsl:when>
        <xsl:when test="$day-of-the-week = 1">Monday</xsl:when>
        <xsl:when test="$day-of-the-week = 2">Tuesday</xsl:when>
        <xsl:when test="$day-of-the-week = 3">Wednesday</xsl:when>
        <xsl:when test="$day-of-the-week = 4">Thursday</xsl:when>
        <xsl:when test="$day-of-the-week = 5">Friday</xsl:when>
        <xsl:when test="$day-of-the-week = 6">Saturday</xsl:when>
        <xsl:otherwise>error: <xsl:value-of select="$day-of-the-week"/></xsl:otherwise>
      </xsl:choose>
    </xsl:template>

  2. copy this code to an XSL file (dayName.xsl) and place it in the designer in the directory as below ( create the directory if not existing):





  3. Use the reload templates button in the Xpath designer, you can use the insert button to add the new function:



  4. The code generated by the designer will now include the external code:



  5. The report will now show the result of the external function get-day-of-the-week-name