Mapping Fundamentals – XSLT Call Templates

Mapping Fundamentals – XSLT Call Templates

I’m creating a new series of posts related to using the BizTalk Mapper.  I know,
it’s certainly less sexy than Pipeline Testing Framework (seriously, follow that link)
or many other BizTalk subjects, but so much of the magic of BizTalk happens in the
mapping.

In my experience, when people are introduced to the BizTalk Mapper they get it very
quickly.  The user interface is straight forward for most of
what you need to do in mapping output.  But certainly not all.  Take for
example some data that looks like this :

<?xml version=”1.0″ encoding=”utf-8″ ?>

<MyRoot>

  <ref qualifier=”D2″ value=”999999999″ />

  <ref qualifier=”XX” value=”999999999″ />

  <ref qualifier=”ZZ” value=”XX-YYYYYYYY” />

  <nm qualifier=”NI” value=”999999999″ />

</MyRoot>

 

Your mission, should you choose to accept it is simple.  Output one and only
one value to destination schema in a node called Identifier which contains either
the value of the ‘value’ attribute of the ‘nm’ element if the matching qualifier is
‘ZZ’ or if that does not exist the ‘value’ attribute of any ‘ref’ element containing
a ‘qualifier’ attribute of ‘ZZ’.  If neither exists, then output the constant
value ‘N/A’.

The catch?  Both nodes can both exist with the proper qualifier,
and ‘nm’ must take precedence in that case.

Now, I’ve no doubt at all that someone could come up with some combination of functoids
which might solve this problem.  But we must remember that in the end a map is
just XSLT and this problem is supremely easy in XSLT and extremely difficult with
the mapper.  The solution, as you’ve likely already guessed, is an XSLT Call
Template Scripting Functoid.

An XSLT Call Template Scripting Functoid lets you inject your own XSLT into the middle
of a map.  No need to take the effort of writing the full XSLT yourself if only
one or two mappings are giving you trouble.  Obviously to be able to write such
a functoid you need to understand XSLT, which if you are mapping is a good skill to
have anyway.  In this simple example we don’t even have to deal with parameters. 
By entering a template as follows, you can solve this problem in a few short lines.

  <xsl:template name=”MapIdentifier”>

    <xsl:variable name=”nmValue” select=”/MyRoot/nm[@qualifier=’ZZ’]/@value”
/>

    <xsl:variable name=”refValue” select=”/MyRoot/ref[@qualifier=’ZZ’]/@value”
/>

    <xsl:element name=”Identifier”>

      <xsl:choose>

        <xsl:when test=”$nmValue”>

          <xsl:value-of select=”$nmValue”/>

        </xsl:when>

        <xsl:when test=”$refValue”>

          <xsl:value-of select=”$refValue”/>

        </xsl:when>

        <xsl:otherwise>N/A</xsl:otherwise>

      </xsl:choose>

    </xsl:element>

  </xsl:template>

 

Some things to remember when working with XSLT Call Templates.

  1. Only use these when needed.  I recently heard Roy Osherove give the same advice
    regarding Regular Expression and he was right.  Both RegEx and XSLT Call Templates
    are more cryptic and harder for someone coming after you to decipher.  Use them
    when you must, when they save you time, but don’t lean on them for everything.
  2. The Template name must be unique within the map.  If you copy-paste the template
    and don’t change the name then only one version will be run.  If you later modify
    one of them and start going nuts trying to figure out why the second isn’t behaving
    properly, check your names.
  3. XSLT Call Templates must create the destination node.  Element or Attribute they
    don’t care, when you write one of these you are taking on the job of outputting that
    node, namespace and all. 

I hope this has been a good quick primer on using XSLT Call Templates.  If you’ve
got a topic you’d like covered, leave a comment!

[Post Script : Before anyone comments, the example XML given was deliberately
rendered similar to an EDI structure because this is a common problem in EDI mappings.]

Passwords & BizTalk

Even with all the time I have spent withBizTalk 2004 and 2006, there is one thing that I will occasionally get tripped on – the fact that exported Bindings and Configuration filesdo not contain passwords.
Forsecurity purposes, BizTalk never shows the existing values of any passwords – whether those passwords are entered during configuration, setting up […]

Software as a Service and BizTalk Server

Software as a Service and BizTalk Server

Next week I’ll be presenting a session about Software as a Service (SaaS) and Business Process at the Microsoft BPI&SOA conference.

I’ve prepared some cool demos to show BizTalk Server interactions with Salesforce.com and Amazon.com. Ahhh announcement: I’ll be showing for first time our new member of the AdapterWorx  family: Amazon.com SQS adapter for BizTalk Server. Here is a summary of the topics that I plan to cover.

 

  • Business Processes and SaaS challenges and benefits.
  • BizTalk Server and SaaS: SOAP, WSE and WCF adapters.
  • Salesforce.com adapter for BizTalk Server
  • Amazon.com SQS adapter for BizTalk Server.
  • Business Rules and SaaS

If you are attending to the conference and you are interested in SaaS and the relationship with BizTalk Server swing by the session and we can have a nice chat.

Share this post: Email it! | bookmark it! | digg it! | reddit!

Session at Upcoming SOA/Business Process/BizTalk Conference

Session at Upcoming SOA/Business Process/BizTalk Conference


Next week we’ve got the SOA and Business Process conference in Redmond, and I’m fortunate enough to be delivering a session. The talk, entitled “Developing and Maintaining Business Rule Solutions” will cover the Business Rules Engine, Windows Workflow Rules Engine, and a 3rd party solution from the nice folks at RuleBurst.


I’ve got something like 7 demos planned, including an application showing dynamic policy updates, rule security, custom rule tracking interceptors and more. Should be fun. If you’re attending, stop by and say hi. Or just heckle me from the back, whatever works for you.


Technorati Tags:

Working with Custom Pipeline Components in BizTalk 2006

Working with Custom Pipeline Components in BizTalk 2006

As you know, a change was made to how custom pipelines components behave in BizTalk Server 2006.  Now they can be placed in the Global Assembly Cache (GAC) as well as in the \Pipeline Components directly.  So what does this mean?  Put them in both place, one place, who knows?

In general, when working with custom pipeline components on a development system the components must be placed in the \Pipeline Components folder to be available for the designer.  When working on a non-development server, putting the components only into the GAC can save on deployment time.  Although this is not really the approach the help guide says (under Developing Custom Pipeline Components), this approach works great in most cases.

Today, I found a big GOT YOU with this approach if the custom component is not put into the GAC before it is used inside Visual Studios.  I found that you must GAC the custom pipeline components BEFORE adding them to the Visual Studios Toolbox or you can run into runtime issues later on.

First, let us take a look at what happens when you add an unsigned and unGACed custom pipeline component to a project.

When you add the component to the Toolbox and drag it onto the Visual Studio design surface, a reference is added to the pipeline component.  As seen below, when the component is not signed and not in the GAC a reference is added to the component in the \Pipeline Components folder.

Not In the GAC

Fig 1: Unsigned and UnGaced 

 

Now, let us take a look at what happens when you add a signed and GACed custom pipeline to a project.

When you add the component to the Toolbox and use it in a pipeline, a reference is added to the pipeline component (same as before).  But this time, the signed and GACed pipeline is referenced to the GACed version of the pipeline component.

 In The GAC

Fig 2: Signed and GACed

 

So why does this matter?  The problem I ran into was I added my custom pipeline component to my solution before I signed it and put it in the GAC.  So when I went to deploy my solution to the development server with the pipeline component only in the GAC, I got a .net runtime error saying it could not find the pipeline in the \Pipeline Components folder. 

Something else to point out is that the pipeline must be put into the GAC before you add the pipeline component to the Toolbox.  Just being signed is not good enough.

The overall moral of the story is<

Session at Upcoming SOA/Business Process/BizTalk Conference

Session at Upcoming SOA/Business Process/BizTalk Conference

Next week we’ve got the SOA and Business Process conference in Redmond, and
I’m fortunate enough to be delivering a session. The talk, entitled “Developing and Maintaining Business Rule Solutions” will cover
the Business Rules Engine, Windows Workflow Rules Engine, and a 3rd party solution from the nice folks at RuleBurst.

I’ve got something like 7 demos planned, including an application showing dynamic policy updates, rule security, custom rule tracking
interceptors and more. Should be fun. If you’re attending, stop by and say hi. Or just heckle me from the back, whatever works for you.

Technorati Tags:

XSLT for versioning my family

XSLT for versioning my family

<xsl:stylesheet version=1.0
xmlns:xsl=http://www.w3.org/1999/XSL/Transform

xmlns:old=http://skonnard.com/family/2001/05

>
<xsl:template match=old:family>
<new:family xmlns:new=http://skonnard.com/family/2006/09>
<xsl:copy-of select=“node()/>
<child dueDate=2007-02-28 name=unknown sex=unknown/>
</new:family>
</xsl:template>
</xsl:stylesheet>