Search This Blog

Sunday, 20 January 2013

Conditionally Highlighting a Row In XML


Conditionally Highlighting a Row

This example demonstrates how to set a background color on every other row. The template to create this effect is shown in the following figure:
Here we are using same RTF which we had used in IF-THEN-ELSE lesson which is shown below


Now we are going to set back ground color for one by one row.
For that we have to place one form filed which is shown below



Just give double click on field and provide proper default text and click on Add Help Text which is shown below


There we are going to write below code

<?if@row:position() mod 2=0?>
<xsl:attribute name="background-color" xdofo:ctx="incontext">lightgray</xsl:attribute>
<?end if?>


Which is shown below


Then click on ‘OK’

Now our RTF looks

Default Text Entry
Form Field Help Text
Description
format;
<?if@row:position() mod 2=0?>
<xsl:attribute name="background-color" xdofo:ctx="incontext">lightgray</xsl:attribute>
<?end if?>
For each alternate row, the background color attribute is set to gray for the row.


Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output



From the above output we get background color on every other row

Cell Highlighting in XML


Cell Highlighting


The following example demonstrates how to conditionally highlight a cell based on a value in the XML file.
In this we are going to use same RTF and RDF which we had used in IF STATEMENT which is shown below
Our RDF: -

Our RTF: -

Now we are going to place two form fields as CH1 AND CH2 in Inv_Amt and in Appr Amt respectively as shown below




Default Text Entry
Form Field Entry
Description
CH1
<?if:INVOICE_AMOUNT>5000?>
<xsl:attribute xdofo:ctx="block" name="background-color"> red</xsl:attribute>
<?end if?>
This field holds the code to highlight the cell red if the debit amount is greater than 5000.
CH2
<?if: approved_amount >5000?>
<xsl:attribute xdofo:ctx="block" name="background-color">green</xsl:attribute>
<?end if?>
This field holds the code to highlight the cell red if the credit amount is greater than 5000.

Save the RTF

Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output