Convert Xml to Html using a Pipeline Xsl Transformation


Hi all,


 


The SDK that you can install with BizTalk has some very nice simple code examples that illustrate how you could tackle a specific problem. Please note however that these are not Enterprise tested solutions and are designed for Demo purposes only.


 


In this example I had been asked to do a demo using a pipeline. This sample was originally designed to use SMTP however considering that Windows Server 2008 doesn’t have this built-in support anymore (whereas Windows Server 2003 does) I changed it to be a simple File to File type of transport. This is much more practical when trying to show a demo.


 


Goal of the Demo:


1.       Pick up an Xml file that we want to convert to Html.


2.       Using a Custom Assembly locate a Xsl transformation file.


3.       Convert the Xml to Html using the Transformation and Custom Code


4.       Send the Html file out


 


Within the SDK there is a nice little project for us to use. Under the following directory (depending upon where you installed it): “C:\Program Files\Microsoft BizTalk Server 2009\SDK\Samples\Pipelines” you can find the folder “XslTransformComponent” and within that there are 2 projects. The first project is a BizTalk project called “SendHtmlMessage” and this is where our pipeline is designed. This is the project that you will deploy to your BizTalk 2009 server. The second project “XslTransfom’ is interesting because it contains the custom code to dynamically find and use a transformation “Xsl” file and apply over incoming xml.


 


First Steps:


When I did this for the first time I copied the whole folder to my C:\projects\pipelines directory so that the original code would stay clean and I would have  backup if things went wrong. Now within the XslTransformComponent folder there should be 2 project folders (SendHtmlMessage  and XslTransformComponent) as well as XslTransformComponent.sln file, .bat files (ignore these as I had only problems within them on Win2K8) and a DocInstance.xml file (which will be used later for testing). Since the .bat file deployment didn’t work for me I had to do a number of things manually. Afterward I was happy for this because by doing it by hand I got a good feeling for how the pieces worked together.  The first manual operation I needed to do was create a strong name file for the BizTalk project. The command line (make sure you use the visual studio command prompt and not the one found with windows) I used was: “>sn –k SendHtmlMessage.snk”. Remember you can’t deploy a BizTalk project unless the assembly has been signed with a strongname. I also like to give my project a name so that I can find it easily in the BizTalk management console. A project can be given a name within the property pages under “Deploy” within Visual Studio. I called my project aptly enough SendHtmlMessage.  ;p


 


Once the strongname is there it shouldn’t be a problem compiling your project. Note that we don’t need a strong name for the XslTransformComponent project nor did I install it to the GAC.


 


Project SendHtmlMessage should already have the 3 following files (and now the strongname file):


1.       Confirmation.xsd


2.       SendHtmlMessage.snk


3.       Xml2HtmlSendPipeline.btp


a.       A send pipeline contains 3 phases: i. Preassemble, ii. Assemble and iii. Encode


b.      Phase i. Preassemble: leave empty


c.       Phase ii. Assemble: the standard Xml Assembler


d.      Phase iii. Encode: XslTransform


 


Project XslTransform should already have the (besides the AssemblyInfo class) only the class: XslTransformer.cs. This is where our custom code for transforming is found.


 


Next Steps:


Once the BizTalk project compiles we can deploy it. Once it is deploy open and refresh the BizTalk Management Console to see if the Application SendHtmlMessage is present. If it is not present recheck that the project deployed from Visual Studio (also check the property pages to make sure the correct SqlServer and Management database is being targeted).


 


Just a few more Steps:


Configure the FileAdapter ports.


1.       Create a Receive Port and Location


a.       Port Name: recprtTransform


                                                               i.      Port Type: one way receive


b.      Receive Location Name: reclocTransform


                                                               i.      Type: File


                                                             ii.      Configure the receive folder: C:\Projects\Pipelines\XslTransformComponent\TEST\IN\


                                                            iii.      File mask is *.Xml


                                                           iv.      Receive Handler: BizTalkServerApplcation


                                                             v.      Receive Pipeline: PassThruReceive


2.       Create a Send Port


a.       Port Name: sndprtTransform


                                                               i.      Port Type: one way receive


                                                             ii.      Configure the receive folder: C:\Projects\Pipelines\XslTransformComponent\TEST\OUT


                                                            iii.      File Name is: New_*.Html


                                                           iv.      Send Pipeline: Xml2HtmlSendPipeline


 


Last Steps:


Now we must copy the XslTransform Dll from the “C:\Projects\Pipelines\XslTransformComponent\XslTransform\bin\Release” folder to the “C:\Program Files\Microsoft BizTalk Server 2009\Pipeline Components” folder.


 


The Transform.xsl file must be copied from the “C:\Projects\Pipelines\XslTransformComponent\SendHtmlMessage” folder to the same “C:\Program Files\Microsoft BizTalk Server 2009\Pipeline Components” folder.


 


Once this is done we can test our work!


Start the BizTalk SendHtmlMessage application.


Find the DocInstance.xml file and copy it (ctrl-c / ctrl-v) to the C:\Projects\Pipelines\XslTransformComponent\TEST\IN\ and if everything worked there should be a Html result in the ..\TEST\OUT folder.


Look at the results, how cool is that?


 


Skip to main content