Talk, talk and more talk about BizTalk

Terminating an XSLT transform during processing

I have run into an instance where I need to terminate and raise an exception from within an XSLT template, based on values (or lack thereof) within the source document.  The XSLT transform is running within a BizTalk map.

The secret is the following little-known XSLT construct, which can be conditionally called at any point in the transform:

<xsl:message terminate="yes">Custom error text</xsl:message>

This will cause the XSLT engine to stop processing immediately, and raise an exception.   This exception, including the custom error text contained within the message segment, can be caught in the BizTalk Orchestration engine by explicitly catching an exception of type Microsoft.XLANGS.BaseTypes.TransformationFailureException.


May 21, 2013 Posted by | BizTalk, XSLT | , | Leave a comment

Xslt snippet – Left pad a string

A quick xslt template to left pad a value:

<xsl:template name="prepend-pad">
  <!-- recursive template to right justify and prepend the value with whatever padChar is passed in   -->
  <xsl:param name="padChar"> </xsl:param>
  <xsl:param name="padVar"/>
  <xsl:param name="length"/>
    <xsl:when test="string-length($padVar) &lt; $length">
      <xsl:call-template name="prepend-pad">
        <xsl:with-param name="padChar" select="$padChar"/>
        <xsl:with-param name="padVar" select="concat($padChar,$padVar)"/>
        <xsl:with-param name="length" select="$length"/>
      <xsl:value-of select="substring($padVar,string-length($padVar) - $length + 1)"/>

August 12, 2009 Posted by | XSLT | , | 1 Comment