Vadim Tabakman

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

Posted by Vadim Tabakman Wednesday, October 10, 2012 3:45:00 PM Categories: Call Web Service Nintex Nintex Workflow Send Notification XSLT
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Friday, October 12, 2012 12:06:46 PM
Kevin

re: Nintex Workflow - XSL Transformation

This is awesome! - I've been doing this, but the hard way.  I would use a loop action and get individual values and built a HTML table using probably 15 actions with a LOT of overhead instead of the simple task that you just created in the simple two action step.

Always wondered what the XSL transformation was, but never had the time to learn.

Question can you apply an alternating color row in the result table?

Friday, October 12, 2012 12:08:38 PM

re: Nintex Workflow - XSL Transformation

Hi Kevin,

it's running you mentioned that.  I was actually looking into that when putting this post together, but I wasn't able to get it to work. Maybe with some more fancy XSL you could do it.  But I tried some CSS3 and unfortunately, I couldn't put css styles into an emal  The <script> node just gets rendered instead of being applied to the HTML.

Thursday, October 25, 2012 10:53:57 PM
raki

re: Nintex Workflow - XSL Transformation

Can you please explain how you placed the HTML in the body of the email ?

Thursday, October 25, 2012 11:02:25 PM

re: Nintex Workflow - XSL Transformation

Hi Raki,

my HTML was in a text variable.  I simply clicked on the Insert Reference button in the Send Notification action and inserted the variable.

You should be able to see it by downloading the workflow. :) Hope that helps.

Sunday, October 28, 2012 4:47:07 PM
Raki

re: Nintex Workflow - XSL Transformation

Vadim Thanks for the reply

When I execute the 'Call Webservice' its works fine and returns one row; however the final output I get is blank. Any idea why ?

 

Tuesday, June 4, 2013 8:54:11 AM
Eli Lawson

re: Nintex Workflow - XSL Transformation

Can you do this with Nintex 2007, when I attempt this.... I keep getting Failed to process response. An 'xsl:stylesheet' element cannot have text node children.

Friday, August 16, 2013 2:36:45 PM
Kevin

re: Nintex Workflow - XSL Transformation

Hi Vadim,

Thanks for the post. I'm also using the GetListItems method to pull all data from a list. Instead of using XSL transform, how can I use the Query XML action to read the results and store the values from a column in a collection? Would the XPATH be something like "rs:data\z:row\ows_ColumnName"?

Thank you,

Kevin

Friday, August 16, 2013 6:43:19 PM

re: Nintex Workflow - XSL Transformation

Hi Kevin,

I don't know the XPath expression off the top of my head.  But there is an XPath builder button in the Query XML action that should help you build the expression you need.

Have you tried that?

If it didn't help, I can check it out over here.

cheers,

Vadim

Thursday, October 10, 2013 9:58:01 AM
Nick

re: Nintex Workflow - XSL Transformation

This is awesome Vadim!  Thanks to you and your great tutorials, I am so much more comfortable with XSLT and Query XML than I ever have been before.  I can think of a dozen ways to apply this to my next projects.  Thanks!  Nick

Thursday, October 10, 2013 9:59:20 AM

re: Nintex Workflow - XSL Transformation

Hey Nick,

that's awesome mate.  I'm glad I could help you out here.  If you come up with some cool idea, I'd love to hear about them.

cheers,

Vadim

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register

Statistics

  • Entries (279)
  • Comments (1769)

Categories