<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gobbledygooks by Richard Hallgren &#187; EXSLT</title>
	<atom:link href="http://www.richardhallgren.com/category/exslt/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardhallgren.com</link>
	<description>.NET, BizTalk and integration focused scribbles</description>
	<lastBuildDate>Fri, 23 Apr 2010 07:13:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How the extend a custom Xslt in BizTalk using EXSLT and the Mvp.Xml project</title>
		<link>http://www.richardhallgren.com/how-the-extend-a-custom-xslt-in-biztalk-using-exslt-and-the-mvpxml-project/</link>
		<comments>http://www.richardhallgren.com/how-the-extend-a-custom-xslt-in-biztalk-using-exslt-and-the-mvpxml-project/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 20:15:55 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[BizTalk 2006]]></category>
		<category><![CDATA[EXSLT]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://www.richardhallgren.com/how-the-extend-a-custom-xslt-in-biztalk-using-exslt-and-the-mvpxml-project/</guid>
		<description><![CDATA[Lately I&#8217;ve been using custom Xslt more and more instead of the BizTalk mapping tool. I still use the mapping tool in easy scenarios when I just need to do some straight mapping or maybe even when I need to concatenate some fields, but as soon as I need to to some looping, grouping, calculations [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been using custom Xslt <a href="http://www.richardhallgren.com/efficient-grouping-and-debatching-of-big-files-using-biztalk-2006/" target="_blank">more</a> and more instead of the BizTalk mapping tool. I still use the mapping tool in easy scenarios when I just need to do some straight mapping or maybe even when I need to concatenate some fields, but as soon as I need to to some looping, grouping, calculations etc I&#8217;ve made a <em>promise</em> to myself to use custom Xslt!</p>
<p>I find custom Xslt so much easier in more complex scenarios and once one get past the template matching and understands how and when to use recursion (No you can&#8217;t reassign a variable in Xslt and you&#8217;re not supposed to!) I find it to be a <strong>dream</strong> compared to the mapping tool. I also find the code so much easier to maintain compared to the result from the mapping tool. I mean someone would have to pay me good money to even start figuring out what <a href="http://www.edsquared.com/content/binary/WindowsLiveWriter/DebugthatBizTalkMap_E215/BadMap_thumb.png" target="_blank">this</a> map is doing. And the scary thing is that if you worked with BizTalk for a while you probably know that maps like this isn&#8217;t that rare! I&#8217;ve even seen worse!</p>
<p>Don&#8217;t get me wrong, Xslt definitely has some <strong>major</strong> <a href="http://biglist.com/lists/xsl-list/archives/200102/msg01384.html" target="_blank">limitations</a>.</p>
<blockquote><p>Some of the acute limitations of XSLT 1.0 I can think of off the top of my head are: </p>
<ul>
<li>The lack of real string comparison
<li>No support for dates
<li>No simple mechanism for grouping
<li>No querying into RTF&#8217;s </li>
</ul>
</blockquote>
<p>And it doesn&#8217;t take long before one runs up against one of these and suddenly you wish you were <strong>back</strong> in mapping tool were we just could add scripting functoid and some code or a external assembly. But then you remember &#8230; (Sorry, I know it&#8217;s painful just to watch it).</p>
<p><a href="http://www.richardhallgren.com/wp-content/uploads/2008/09/windowslivewriterhowtheextendacustomxsltinbizt.xmlproject-138fabadmap-thumb-2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="400" alt="BadMap_thumb" src="http://www.richardhallgren.com/wp-content/uploads/2008/09/windowslivewriterhowtheextendacustomxsltinbizt.xmlproject-138fabadmap-thumb-thumb.png" width="504" border="0"></a> </p>
<p><strong>There has to be a better way of doing this and <em>combining</em> the best out of the two worlds! </strong></p>
<p>I started looking into to how BizTalk actually solves combining Xslt and the possibility to use external assemblies. After a couple of searches I found Yossi&#8217;s <a href="http://www.sabratech.co.uk/blogs/yossidahan/archive/2005_08_01_archive.html" target="_blank">nice article</a> that explained it to me (from 2005! I&#8217;m behind on this one!) and it even turns out that there an <a href="http://msdn.microsoft.com/en-us/library/ms966408.aspx">example</a> in the BizTalk SDK. </p>
<p>Ok, so now I had what I need. I started a new class library project and began writing some date parsing methods, some padding methods and so on. </p>
<p>It somehow however felt wrong from the start and I got this grinding feeling that I must be reinventing the wheel (I mean these are well know limitations of Xslt and must have been solved before). Even worse I also felt that I was creating a stupid <em>single point of failure</em> as I started using the component from all different maps in my projects and I have actually seen how much pain a bug in similar shared dll:s could cause. Basically <em>a small bug in the component could halt all the process using the library</em>! Finally I realized that this kind of library would be under constant development as we ran into more and more areas of limitations in the our Xslt:s and that would just <strong>increase</strong> the risk of errors and mistakes. </p>
<p>After some further investigation I found <a href="http://www.exslt.org/">EXSLT</a> which looked like a solution to my problems! A <em>stable, tested</em> library of Xslt extensions that we could take dependency on as <strong>it&#8217;s unlikely to have any bugs and that should include the functionality we&#8217;re missing in standard Xslt!</strong></p>
<h3>How I used EXSLT in BizTalk</h3>
<p>These days it&#8217;s the <a href="http://www.codeplex.com/MVPXML/People/ProjectPeople.aspx">Xml Mvp crowd</a> over at the <a href="http://www.codeplex.com/MVPXML">Mvp.Xml project</a> who develops and maintains the .NET implementation of EXSLT. So I downloaded the latest <a href="http://www.codeplex.com/MVPXML/Release/ProjectReleases.aspx?ReleaseId=4894">binaries</a> (version 2.3). Put the the <em>Mvp.Xml.dll</em> in the GAC. Wrote a short custom extension Xml snippet that looked like this (using what I&#8217;ve learnt from <a href="http://www.sabratech.co.uk/blogs/yossidahan/archive/2005_08_01_archive.html">Yossi&#8217;s article</a>).</p>
<pre class="xml" name="code">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;ExtensionObjects&gt;
    &lt;ExtensionObject
     Namespace="http://exslt.org/dates-and-times"
     AssemblyName="Mvp.Xml,
     Version=2.3.0.0, Culture=neutral,
     PublicKeyToken=6ead800d778c9b9f"
     ClassName="Mvp.Xml.Exslt.ExsltDatesAndTimes"/&gt;
&lt;/ExtensionObjects&gt;</pre>
<p>All you define is the <em>Xml namespace </em>you like to use in your Xslt to reference the dll, the <em>full assembly name</em> and finally the <em>name of the class</em> in <em>Mvp.Xml.Exslt</em> you want to use (make sure you also download the source to Xml.Mvp, it helps when looking up in what classes and namespaces different methods are placed). </p>
<p>That means you need one <em>ExtensionObjects</em> block for each class you want you use which really isn&#8217;t a problem as the methods are nicely structured based on there functionality.</p>
<p>Then we can use this in a Xslt like this:</p>
<pre class="xml" name="code">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:S1="http://ExtendedMapping.Schema1"
                xmlns:S2="http://ExtendedMapping.Schema2"
                xmlns:exslt="http://exslt.org/dates-and-times"
                version="1.0"&gt; 

    &lt;xsl:template match="/"&gt;
        &lt;S2:Root&gt;
            &lt;Field&gt;
                &lt;xsl:value-of select="exslt:dateTime()"/&gt;
            &lt;/Field&gt;
        &lt;/S2:Root&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>Which gives us the below output. <strong>Notice the current time and date! Cool!</strong></p>
<pre class="xml" name="code">&lt;S2:Root xmlns:S1="http://ExtendedMapping.Schema1" xmlns:S2="http://ExtendedMapping.Schema2" xmlns:exslt="http://exslt.org/dates-and-times"&gt;
  &lt;Field&gt;2008-09-05T20:45:13+02:00&lt;/Field&gt;
&lt;/S2:Root&gt;</pre>
<p>All you then have to do in you map is to reference the Xslt and the extension Xml.</p>
<p><a href="http://www.richardhallgren.com/wp-content/uploads/2008/09/windowslivewriterhowtheextendacustomxsltinbizt.xmlproject-138facustom-extension-in-map-2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="269" alt="Custom Extension In Map" src="http://www.richardhallgren.com/wp-content/uploads/2008/09/windowslivewriterhowtheextendacustomxsltinbizt.xmlproject-138facustom-extension-in-map-thumb.png" width="431" border="0"></a> </p>
<p>Just as final teaser I&#8217;ll paste a few methods from the <a href="http://www.exslt.org/">EXSLT documentation</a></p>
<p>Some <em>string</em> methods:</p>
<ul>
<li>str:align()
<li>str:concat()
<li>str:decode-uri()
<li>str:encode-uri()
<li>str:padding()
<li>str:replace()
<li>str:split()
<li>str:tokenize() </li>
</ul>
<p>Some <em>date and time</em> methods:</p>
<ul>
<li>date:add()
<li>date:add-duration()
<li>date:date()
<li>date:date-time()
<li>date:day-abbreviation()
<li>date:day-in-month()
<li>date:day-in-week()
<li>date:day-in-year()
<li>date:day-name()
<li>date:day-of-week-in-month()
<li>date:difference()
<li>date:duration()
<li>date:format-date()
<li>date:hour-in-day()
<li>date:leap-year()
<li>date:minute-in-hour()
<li>date:month-abbreviation()
<li>date:month-in-year()
<li>date:month-name()
<li>date:parse-date()
<li>date:second-in-minute()
<li>date:seconds()
<li>date:sum()
<li>date:time()
<li>date:week-in-month()
<li>date:week-in-year()
<li>date:year() </li>
</ul>
<p>As if this was enough (!) the Mvp Xml project added a couple of there own methods! What about <strong><em>string lowercase</em></strong> and <strong><em>string uppercase &#8211; </em>all in Xslt!</strong> And about 30 new date-time related methods extra to the standard ones already in EXSLT!</p>
<p>Check out the full documentation <a href="http://www.xmllab.net/mvpxml/default.aspx" target="_blank">here</a>!</p>
<p>Let me know how it works out for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardhallgren.com/how-the-extend-a-custom-xslt-in-biztalk-using-exslt-and-the-mvpxml-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
