If you follow my blog or already saw one of my presentations in BizTalk innovation Days events about BizTalk Mapper Patterns and Best Practices, you already notice that I avoid using Custom XSLT files for solving a mapping problem.
I only recommend using custom XSLT files:
- If you are dealing with huge message and High Performance is one of the primary requirements (and even then this maybe can be avoid)
- Or if you already have a custom XSLT file provided by another team, or from another system that you can re-use in your map. In this case don’t try to reinvent the wheel!
But again, this is my personal opinion. You may argument that XSLT automatically generated code by the BizTalk mapper complier cannot perform as well as the personal Custom-XSLT code! And yes, I agree with you… in most of the cases… but it also depends on the approach that 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, and this will also be addressed in my upcoming eBook in more detail, however I let you with two statements:
- In most scenarios you wouldn’t really notice too much difference between using the BizTalk Mapper and a custom XSLT file;
- I can prove to you that using properly the BizTalk Mapper can have the same performance that a custom XSLT file! (of course that can always be exceptions)
However if you are using an external XSLT file at least you should follow some of this best practices:
TIP 1: Always Add your custom XSLT files to the solution
You should always add the External custom XSLT files to your solution, so that they can be easily find and can be added to the source control.
TIP 2: Give it a proper name
Don’t call it “ExternalXSLT” or “CustomXSLTCode”, give it a proper name to the custom XSLT file that could identify the map.
- For example: “<name of the map>-XSLTFile.xsl”
TIP 3: Add Standard XML Comments
You should add standard XML comments: “<!– Comment –>”, inside the custom XSLT code. As many time you think that it is important to explain little parts of the process/code.
... <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> …
TIP 4: Rename the page grid
If you are using an external XSLT file, at least rename the default grid page (Page 1) to a name that draws attention to this fact, for example: “ThisMapUseAnExternalXSLTFile”. At least this way new BizTalk developer can easily read and understand that this maps uses an external XSLT file.
Note: The best part in being a speaker at BizTalk events, is that we can discuss with the attendees and get feedback. I really love this part! And this last tip was given by Mikael Sand while we were discussing this topic, probably while we were taking a beer in Norway :)
Feel free to comment or add more tips to implement best practices.
The sample code is available for download in Code Gallery:.
BizTalk Mapper: External Custom XSLT file vs BizTalk Mapper (Best Practices) (69.5 KB)
Microsoft Code Gallery