Hi there AppWorks fans,
Welcome to a new installment of AppWorks tips.
When you connect with people you start to see and hear things at a higher level! This time a high-valuable feature I would never have found if it wasn’t for my comrade in crime (the godfather of BPM…you know who you are!); This person noted me about the greatest of all webservices. Yes, you’ll be amazed what would be possible after the reading of this blog post. It all has to do with the transformation of data before you expose it any further. For our platform, this data will be in XML format and when you know a bit of eXtensible Stylesheet Language Transformations, the world is open for any complex transformation skills!
During this introduction, I also spotted an old friend on the interwebs…“The Apache FOP Project”. It’s not for this post, but I put it on my backlog; Spitting out PDFs based on XML data is a user story in every project! 😏 Why using complex products when you can do it with a couple of coding-lines and standardization on stylesheets!
Let get right into it…
For my journey I start simple with a basic XML file in my good old Notepad++ with the enablement of the XML Tools plugin. My second file is this XSLT file to make a conversion on the XML. Both files are open in my Notepad++; Now move to the ‘Plugins’ action in the top bar and open the ‘XML Tools’. You see a long list of actions where ‘Pretty print’ is a common action to do, but I would like to move to the action ‘XSL Transformation’:
Make sure you have the XML file in view as this action uses it as input.
Now, select the XSL file and hit the ‘Transform’ button to see the outcome…It’s magic! 🔮 From one XML to another XML; You can even product an HTML page with this technique, but that’s not the point of this post…Just that you know!
I already have some basic XSLT knowledge; If you don’t have it, here are some resources to start:
The next question would be: How can we use this transformation skill in our beloved AppWorks platform? Well, as AppWorks is service oriented and XML minded, it would be impossible not to have a service available that answers our question…And there is! With the fancy name
XSLtransformGeneric living in the namespace
AHA! Let’s have a look in the ‘Web Service Interface Explorer’ artifact:
Where are you waiting for…Right-click it and do a first test request. The input? Yes, my friend…As you wish (The XML- and XSL-parts are from the files at the start of this post!):
This is the output as a result on this service call:
Isn’t that a beauty of a service!? Also, nicely in ‘Pretty print’ format…That’s exactly why we love AppWorks…The “App” just “works”! 🤗
Now that we know the service call, it’s easy to use it in any future BPM, for any XML transformation required. Let’s go through some open questions from my side…
Is XSLT 2.0 supported?
Well, partly!?!? Yes, you read it correctly and I also find it strange as this XSLT 2.0 function is NOT working:
<xsl:value-of select="current-date()"/>. Guess what; This XSLT 2.0 function is working fine:
<xsl:value-of select="upper-case('hello world')"/>…That’s from my service call in AppWorks (not Notepad++)! Even with the stylesheet version still at
1.0…”Stranger Things”! I’m not diving into this, but from what I understand “2.0” relates to XSLT 2.0, but also xPath 2.0 and maybe AppWorks does something under the hood!? Any comment is welcome…
Is there a faster way to build XSLT?
Yes, I can remember a tool from long ago called Oxygen; Not free, but works great. I see Visual Studio Code has no direct way to do this trick; You could use a plugin! I saw also another tool from the past named Cooktop…It’s just memories; Don’t use it as it’s not developed anymore. Notepad++ is already shown!
See if the tool supports “debugging”…You eventually need it, but that’s just my experience! 😁 For a quick XSLT assessment use this.
Do we need this good old stuff in our XSLT document?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt">
Nope, as our beloved platform already makes it a “pretty print” in the response; You can use it in your external editor to pretty print the output!
What about theses weird statements?
Well, have a read here
How about a for-loop with
Or what about calling a template (or method/function):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Or even better…do a
There is sooooo much more to explore here, but that’s a task for you to experience…I’m just giving you a heads-up on your creativity! 🤠
That’s our “DONE” for this post. A high-valuable skill is shared with this post and the world is at your feed when it comes to XML transformation using the techniques behind XSLT. I definitely see a use-case in any AppWorks project for the
XSLtransformGeneric webservice shared in this post…Now it’s up to you how you use it. As with everything…”Great power comes with great responsibility”, so be thinkable on the implementations and keep things simple. Have a great transformation weekend, and I will see you next week with on another interesting AppWorks Tips topic! 😉