Welcome again to another BizTalk Server Best practices, Tips, and Tricks blog post! In my previous blog posts, I discussed some essential tips and tricks for BizTalk Server administrators:
And for BizTalk Server Developers:
Today I will speak about another critical Best practice, Tips, and Tricks, this time for BizTalk Server developers: Using Custom XSLT files inside your BizTalk Server maps.
Personally, I’m not a big fan of using External Custom XSLT files for solving a mapping problem, and I do try to avoid implementing this strategy, except if:
You will always find people that may argue that XSLT automatically generated code by the BizTalk mapper compiler cannot perform as well as the personal Custom-XSLT code! And yes, I agree with you, but in most cases, the performance difference it’s ridiculously low, and it also depends on the approach you are implementing to solve the problem.
The real secret is to find the best of both worlds: BizTalk Mapper and custom XSLT together. I can spend many hours discussing this topic, but you can always know more about this topic in my free book: BizTalk Mapping Patterns & Best Practices.
However, I let you with two statements:
However, if you are using an external XSLT file, at least you should follow some of these best practices:
You should always add the external custom XSLT files to your solution, if possible side-by-side with the map (same folder) so that:
Don’t call it ExternalXSLT or CustomXSLTCode. Give a proper name to the custom XSLT file. A name that could easily identify and easily associated with the map.
You should add standard XML comments: <!– Comment –> inside the external custom XSLT code.
Whenever you think that it is important to explain little parts of the process/code, you should always add comments. This will help you document the transformation and share knowledge between the teams.
... <xsl:template match="/s0:Order"> <xsl:variable name="var:v1" select="userCSharp:GetCurrentDateTime()" /> <ns0:SAPOrder> <OrderId> <xsl:value-of select="Orderheader/OrderNumber/text()" /> </OrderId> <ClientId> <!-- This is a dummy value, in real scenarios we probably get this value from an external system or DB base on the client name--> <xsl:text>1</xsl:text> </ClientId> <Dates> …
If you use an external XSLT file, at least rename the default grid page (Page 1) to a name that draws attention to the fact this map is using an external XSLT file, for example:
At least this way, a new BizTalk developer or an inexperienced developer can easily read and understand that this map uses an external custom XSLT file.
Stay tuned for the following BizTalk Server Best practices, Tips, and Tricks.