BPC-Components

Home > Products > BPC PowerForms - Silverlight > Knowledge Base > Printing > XSLT Printing Step by Step using PowerForms

XSLT Printing Step by Step using PowerForms

PowerForms provides an out of the box printing functionality using the layout of the run-time designer configuration.

In order to build our own custom reports, we have to use the XSLT based printing provided by PowerForms.

This is a step by step guide on designing your custom reports for users with minimum or no prior knowledge of XSLT.

Since the final output of the pritout is send to the browser, minumim Html knowledge is required.

Example

For our example we will assume we already have a simple list using PowerForms.

Our list will use a list with Articles.

 

The columns of this list are shown in the screen below :

The out of the box print layout is something like the following :

Now lets try to customize the print layout to fit our needs.

We should start from an empty XSLT file. Copy the following text and place it inside a text file (using a text editor, i.e. Notepad).

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">

</xsl:template>

</xsl:stylesheet>

Now give the file a name that will assosiate it with the Articles list (i.e. articles.txt) and upload it in the "BPC PowerForms Binaries" document library or any other document library you already use for public use.

For this example we will upload the file in the "http://SERVERNAME/BPC PowerForms Binaries" library which is created during PowerForms installation.

Now we must apply the xslt file url to the form.

We edit an existing record from the Articles list using PowerForms, open the designer, select the OPTIONS section and in the Printing properties of the designer, we apply the complete path of the file in the "Print Template" property.

 If we try to use the print button at this moment, we will get an empty page which is expected since we haven't made any changes in the contents of the file.

Now, since the file is in the document library, click on the file and select "Edit" to edit it in a text editor.

From now on, each time we save the file, we will be able to test the print layout.

We want to build a report that will include 2 columns : One for the Caption and one for the Contents of each control we use.

To do that we should create an HTML table inside the file.

This is how the xslt file becomes :

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:msxsl="urn:schemas-microsoft-com:xslt"

exclude-result-prefixes="msxsl">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">

<table cellspacing="0" cellpadding="4" >

<tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Title</td>

<td><xsl:value-of select="*/*[@ControlName='c_Title']"/></td>

</tr>

</table>

</xsl:template>

</xsl:stylesheet>

We added a table with a single row and 2 columns.

We have changed the background color of the first cell as well as font weight and cell width.

Than inside the second cell, we used the "<xsl:valuue-of select="*/*[@ControlName='c_Title']"/>" tag in order to display the value of the Title.

 Now to add more rows in our report, we use the same pattern adding tags of the following format:

<tr>   (OPEN ROW)

<td>   (OPEN CELL)

    CAPTION

</td>   (CLOSE CELL)

<td>   (OPEN CELL)

   <xsl:valuue-of select="*/*[@ControlName='c_Title']"/>   (CONTROL VALUE)

</td>   (CLOSE CELL)

</tr>    (CLOSE ROW)

 So after adding more fields in our report, the xslt file should become something like this :

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:msxsl="urn:schemas-microsoft-com:xslt"

exclude-result-prefixes="msxsl">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">

<table cellspacing="0" cellpadding="4" style="font-family:Verdana;">

<tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Title</td>

<td><xsl:value-of select="*/*[@ControlName='c_Title']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Category</td>

<td><xsl:value-of select="*/*[@ControlName='c_Category']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Sub Category</td>

<td><xsl:value-of select="*/*[@ControlName='c_SubCategory']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Priority</td>

<td><xsl:value-of select="*/*[@ControlName='c_Priority']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Article Type</td>

<td><xsl:value-of select="*/*[@ControlName='c_ArticleType']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Author</td>

<td><xsl:value-of select="*/*[@ControlName='c_ArticleAuthor']"/></td>

</tr><tr>

<td style="background-color:LightGray;font-weight:bold;width:150px;">Tags</td>

<td><xsl:value-of select="*/*[@ControlName='c_Tags']"/></td>

</tr>

</table>

</xsl:template>

</xsl:stylesheet>

We changed the font family to Verdana and testing our print layout would give us something like this :

Besides from building your report from scratch, you could use an html editor to prepare the final report layout and then you should place the html content inside the <xsl:template> and </xls:template> tags and add the <xsl:value-of XXX> tags wherever you want to apply control values from the underlying list item. 

Note 1 : As you can see in the above example, the control name is used to print data values, since PowerForms allows users to print any control value instead of list item value, allowing the users to also print controls with calculated values or any other control placed on the form.  

Note 2 : XSLT performs special handling for some characters like "&". You should replace the "&" character with the "&amp;" equivalent otherwise the transformation will fail.