Nintex Workflow – XSL Transformation

What is XSL?

XSL stands for Extensible Stylesheet Language.  It is used to transform an XML document into something else that is more user friendly.  A most common practice is transform XML into HTML.

In a Nintex Workflow scenario, there are a number of situations where you have an XML structure.  The most obvious one that stands out, is the result of a web service call.

To show an example of this, we will call the SharePoint Lists.asmx web service and specifically the GetListItems web method.

The SOAP packet to call this web service looks like this :

<?xml version=”1.0″ encoding=”utf-8″?>
<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/“>
    <soap:Body>
        <GetListItems xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
            <listName>{Common:ListName}</listName>
            <viewName></viewName>
            <query></query>
            <viewFields></viewFields>
            <rowLimit></rowLimit>
            <queryOptions><QueryOptions/></queryOptions>
            <webID></webID>
        </GetListItems>
    </soap:Body>
</soap:Envelope>

This query is simply asking for all the information of the current list that the workflow is running on.

The XML that gets received looks like this:

<listitems xmlns:s=”uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882″ xmlns:dt=”uuid:C2F41010-65B3-11d1-A29F-00AA00C14882″ xmlns:rs=”urn:schemas-microsoft-com:rowset” xmlns:z=”#RowsetSchema” xmlns=”http://schemas.microsoft.com/sharepoint/soap/“>
  <rs:data ItemCount=”3″>
    <z:row ows_Attachments=”0″ ows_LinkTitle=”test1″ ows_Age=”40.0000000000000″ ows_GetListI=”2″ ows_MetaInfo=”1;#” ows__ModerationStatus=”0″ ows__Level=”1″ ows_Title=”test1″ ows_ID=”1″ ows_UniqueId=”1;#{EAC0B6E4-9E71-4240-A776-CE986DF19FD3}” ows_owshiddenversion=”2″ ows_FSObjType=”1;#0″ ows_Created_x0020_Date=”1;#2012-10-09 23:04:19″ ows_Created=”2012-10-09 23:04:19″ ows_FileLeafRef=”1;#1_.000″ ows_PermMask=”0x7fffffffffffffff” ows_Modified=”2012-10-09 23:04:39″ ows_FileRef=”1;#Lists/XSL/1_.000″ />
    <z:row ows_Attachments=”0″ ows_LinkTitle=”test2″ ows_Age=”44.0000000000000″ ows_MetaInfo=”2;#” ows__ModerationStatus=”0″ ows__Level=”1″ ows_Title=”test2″ ows_ID=”2″ ows_UniqueId=”2;#{D0777DF9-A869-4D83-958C-0A1232A4AE0C}” ows_owshiddenversion=”1″ ows_FSObjType=”2;#0″ ows_Created_x0020_Date=”2;#2012-10-09 23:04:45″ ows_Created=”2012-10-09 23:04:45″ ows_FileLeafRef=”2;#2_.000″ ows_PermMask=”0x7fffffffffffffff” ows_Modified=”2012-10-09 23:04:45″ ows_FileRef=”2;#Lists/XSL/2_.000″ />
    <z:row ows_Attachments=”0″ ows_LinkTitle=”test3″ ows_Age=”31.0000000000000″ ows_MetaInfo=”3;#” ows__ModerationStatus=”0″ ows__Level=”1″ ows_Title=”test3″ ows_ID=”3″ ows_UniqueId=”3;#{6D31928A-E9CD-44BA-AF46-5C0C2C0B1F6A}” ows_owshiddenversion=”1″ ows_FSObjType=”3;#0″ ows_Created_x0020_Date=”3;#2012-10-09 23:04:51″ ows_Created=”2012-10-09 23:04:51″ ows_FileLeafRef=”3;#3_.000″ ows_PermMask=”0x7fffffffffffffff” ows_Modified=”2012-10-09 23:04:51″ ows_FileRef=”3;#Lists/XSL/3_.000″ />
  </rs:data>
</listitems>

The XML we get back is not pretty.  It’s definitely not something for an end user.  So as a workflow designer, our job is to beautify this information and make it more friends to an end user.

The Call Web Service action supports an XSL transformation.

Call Web Service

Just expand the “Result Processing” section and then you’ll be able to enter the XSL that you want to use.  In our case, the XSL looks like this :

<?xml version=”1.0″?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0″>
 <xsl:output indent=”no” method=”html”/> -<xsl:template match=”/” name=”ShowVariables”>
  <html>
   <body>
    <h2>My Items</h2>
    <table border=”1″>
     <tr bgcolor=”#9acd32″>
      <th>Title</th>
      <th>Age</th>
     </tr>
     <xsl:for-each select=”//*[name()=’z:row’]”>
      <tr>
       <td>
        <xsl:value-of select=”@ows_Title”/>
       </td>
       <td>
        <xsl:value-of select=”format-number(@ows_Age,’#,###.00′)”/>
       </td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

The List that we will test with is quite simple:

List

The impressive thing about all of this, is that the workflow required to get all the information from this list, transform it into something visually appealing and send it in an email just take 2 actions:

Workflow

The end result is an email and the HTML table that we get looks like this:

Email

Conclusion

If you don’t have much experience with XSL, I find w3schools to be a great learning site – http://www.w3schools.com/xsl/

This post is a very simple XSL transformation of XML to HTML.  You can do so many more things with it.  I’ll leave this to the readers to use their imagination.  But just the fact that you can take XML results and convert them into a nice report that can be emailed to management, rather than flat email text and you can automate it in Nintex Workflow with just a couple of action, that’s pretty amazing.

Downloads

Nintex Workflow 2010 : v2.3.5.0

Download the XSL Transformation Workflow

Leave a Reply

Your email address will not be published. Required fields are marked *