Conditionally Displaying Columns in Excel output – RTF Template
In this article we shall see how to define RTF template for displaying
column conditionally in excel output.
Consider below student XML data, which lists details of each
student, our requirement is to display “Avg Marks” column only when ROLE is “ADMIN”,
for other roles “Avg Marks” column should NOT appear.
<STUDENTINFO>
<ROLE>ADMIN</ROLE>
<LIST_G_STUDENT>
<G_STUDENT>
<ROLLNO>1111</ROLLNO>
<NAME>ADAM</NAME>
<CLASS>10</CLASS>
<PASSYR>2016</PASSYR>
<AVGMARKS>52</AVGMARKS>
</G_STUDENT>
<G_STUDENT>
<ROLLNO>2222</ROLLNO>
<NAME>BILL</NAME>
<CLASS>10</CLASS>
<PASSYR>2017</PASSYR>
<AVGMARKS>63</AVGMARKS>
</G_STUDENT>
<G_STUDENT>
<ROLLNO>3333</ROLLNO>
<NAME>MARY</NAME>
<CLASS>9</CLASS>
<PASSYR>2016</PASSYR>
<AVGMARKS>72</AVGMARKS>
</G_STUDENT>
<G_STUDENT>
<ROLLNO>4444</ROLLNO>
<NAME>JOHN</NAME>
<CLASS>9</CLASS>
<PASSYR>2017</PASSYR>
<AVGMARKS>63</AVGMARKS>
</G_STUDENT>
<G_STUDENT>
<ROLLNO>5555</ROLLNO>
<NAME>PETER</NAME>
<CLASS>8</CLASS>
<PASSYR>2017</PASSYR>
<AVGMARKS>82</AVGMARKS>
</G_STUDENT>
</LIST_G_STUDENT>
</STUDENTINFO>
RTF Template
with out any condition is like this
Sample
output without any condition
Now lets add
condition for “Avg Marks” column as shown in below screenshot
"IFADMIN" at
column header level is defined as "<?if@column:ROLE="ADMIN"?>", as shown below:-
"END IF" at column
header level is defined as "<?END IF?>"
"IFADMIN" in
column data is defined as "<?if@column:../../ROLE="ADMIN"?>", as shown below:-
Sample
output when role = “ADMIN”
Sample
output when role = “TEACHER”
Short and ckear
ReplyDelete