cancel
Showing results for 
Search instead for 
Did you mean: 

XSL Transformation of repeating section to html

Nintex Newbie
6 7 7,420

Repeating section as html table in mail describes how to transform a repeating section to html. It was done by template rules. Problem was it outputs all the Text Data that is present in the XML file even if no template rule is defined for a repeating section control since then applies the default rule for text.

To avoid that here for-each is used in stylesheet. Only these fields that have to appear in the output must be specified.

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

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <xsl:output method="html" />

   <!-- transform repeating section from xml to html -->

   <xsl:template match="/">

      <table border="1" width="100%" style="border-collapse:collapse;background-color:#eee;border:1px solid;color:black;font-size:100%;font-family:arial,helvetica,sans-serif;">

         <thead>

            <tr>

               <td>first name</td>

               <td>name</td>

               <td>company</td>

            </tr>

         </thead>

         <tbody>

            <xsl:for-each select="//Items/Item">

               <tr>

                  <td>

                     <xsl:value-of select="first_name" disable-output-escaping="yes" />

                  </td>

                  <td>

                     <xsl:value-of select="last_name" disable-output-escaping="yes" />

                  </td>

                  <td>

                     <xsl:value-of select="company" disable-output-escaping="yes" />

                  </td>

               </tr>

            </xsl:for-each>

         </tbody>

      </table>

   </xsl:template>

</xsl:stylesheet>

Except for the stylesheet, everything remains as in Repeating section as html table in mail .

7 Comments
Nintex Newbie

Hi Manfred, 

I have tried your steps of converting repeating section to HTML format and storing in a workflow variable.

Everything works perfect ! And, i see the result in HTML format. I have small issue here, I want to display repeating section in HTML format on 'Workflow Task Form' .

But when I show the 'WorkflowVariable_HTML' on my task form, it is just getting displayed as plain HTML. Even I tried this, In nintex form designer, under General Controls --> There is a 'Rich Text' control listed --> Utilizing this and 'In settings', I linked this control to 'WorkflowVariable_HTML', but no luck. Any work around for this?

The reason for showing this on 'Task Form' because, all my approvers open this task form to approve and they want to see all fields on this form.

Nintex Newbie

Hi Nagarjuna,

to get HTML rendered in Form created a Single Line Textbox control, insert by Insert Referenz WorkflowVariable_HTML variable containing the html coding and give it a Client ID JavaScript variable name, e.g. html_var.
. The control itself has to be made invisible on the form by css. Also create a Rich Text control and give it CSS class render_html and by JQuery the html content of the control will be replaced by the content of Your HTML variable:

NWF$(document).ready(function () {
  NWF.FormFiller.Events.RegisterAfterReady(function () {
    try {
          NWF$('.render_html').html(NWF$('#'+ html_var).val());
    } catch (err) {    }});
});

But in Your case it it better to assign Repeating section control to a workflow variable and define Repeating section with controls also in Task Forms and assign it to same workflow variable. This way repeating section is shown same in all Forms.

Kind regards

Manfred

Nintex Newbie

Hi Manfred,

I have tried your first approach and it worked perfectly well. Now, i am able to show HTML formatted table on 'Workflow Notification Form'.

Apart, I have two small issues here, 

1. If a table row is blank, next row is binding its position..

                  <td>

                     <xsl:value-of select="last_name" disable-output-escaping="yes" />

                  </td>                 

                  <td>

                     <xsl:value-of select="company" disable-output-escaping="yes" />

                  </td>

If 'last_name' is returned blank, 'Company' records are showing under 'last_name' header, leaving 'Company' blank. Is there way to check for blank row and replace it with 'N/A' ? In my case, this is what i am seeing.. 

  

Actually, 'Task Profile' row need to be left blank and the dates should be under 'Date Of Job'

2. Second thing, if you see my date, it is getting returned as '01/03/2017 00:00:00'. Can we parse it and get only '01/03/2017' ?

Thank you so much for your help.

Nintex Newbie

take a look at Tricky whitespace handling in XSLT  (xsl:preserve-space)

and search for 'xslt format date'.

Nintex Newbie

Hi Manfred Lauer,

How do we filter by company and only insert those companies in the email?

Nintex Newbie

replace

<xsl:for-each select="//Items/Item">

by

<xsl:for-each select="//Items/Item[company='companyname2filter']">

Nintex Newbie

Thank you Manfred Lauer, that helped!