BL Scripting with XSLT

Overview    

When a more complicated operations than standard business rule can offer is required for a field transformation, the XSLT script action can be used. User should specify certain FIX Field [and Field Length] in the Script instruction. Then rules processor extracts the field value, apply the specified transformation and assigns the obtained result to the field.

XSLT Script instruction in the Action section of a business rule:

BL_Config.xml:

 

<Script Language="XSLT" Field="213" LengthField="212" FileName="script1.xslt" >
    <Param Name="AcctParam">'JBDFLLC'</Param>
</Script>

This instruction causes the rule processor to get value of FIX field 213, loads XSLT script from file "script1.xslt", applies the transformation to the value passing there parameter AcctParam and assigns the resulting value to field 213.

LengthField  attribute is optional. If it is specified then rule processor sets the length to the result. This attribute must be specified if the field has FIX type Raw Data.

The specification for XSLT can be found at W3C. Apache Xalan is used as internal XSLT processor.

Examples  

The sample of XSLT instruction and script is shown below:

BL_Config.xml:

 

<!DOCTYPE FIXEdge SYSTEM "BusinessLayer.dtd">
<FIXEdge>
  <!-- All rules are applied independently --> 
  <BusinessLayer>
    <!-- The first rule.--> 
    <Rule>     
      <!-- Check where the message is received from --> 
      <Source>
        <!-- Message received from any FIX session --> 
        <FixSession SenderCompID=".*" TargetCompID=".*"/>
      </Source>
      <!-- Check the message content --> 
      <Condition>
        <!-- Message with any value of MsgType --> 
        <MatchField Field="35" Value=".*"/>
      </Condition>
      <!-- Apply action if Source and Condition succeeded --> 
      <Action>
        <!--
          -- Apply XSLT script from file 'script1.xslt' to the value
          -- of FIX field 213; since 213 is a RawData field the field
          -- 212 that contains its length is also mentioned.
          -- String ' world' will be used to substitute parameter with name
          -- 'param1'; String '!' will be used to substitute parameter
          -- with name 'param2';
          --> 
        <Script Language="XSLT" Field="213" LengthField="212" FileName="script1.xslt" >
            <Param Name="param1">' world'</Param>
            <Param Name="param2">'!'</Param>
        </Script>
        <!-- Send message --> 
        <Send>
          <!--
            -- Send message to the FIX session according to the SenderCompID
            -- and TargetCompID fields in this message.
            --> 
          <FixSession />
        </Send>
      </Action>
    </Rule>
  </BusinessLayer>
</FIXEdge>

 

script1.xslt:

 

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:output encoding='US-ASCII'/>
<!-- Declaration of the parameter with the default value --> 
<xsl:param name="param1" select="'default value'"/>
<!-- Declaration of the parameter with the default value --> 
<xsl:param name="param2" select="'default value'"/>
<!-- Find '<doc>' element inside XML --> 
<xsl:template match='doc'>
    <!-- Replace with '<out>' element --> 
  <out>
    <!-- Remain text in element unchanged --> 
    <xsl:value-of select="."/>
    <!-- Append value of the first input parameter --> 
    <xsl:value-of select="$param1"/>
    <!-- Append value of the second input parameter --> 
    <xsl:value-of select="$param2"/>
  </out>
</xsl:template>
</xsl:stylesheet>

 

Source FIX message:

  8=FIX.4.4.9=145.35=8.49=A0.56=I0.34=2.52=20010719-08:22:55.212=60.213=<?xml version='1.0' encoding='ISO-8859-1' ?><doc>Hello</doc>.37=ORDER-1.17=0.32=0.31=0.0.150=0.39=0.55=ORCL.54=1.38=100.40=1.15=USD.151=0.14=0.6=0.0.10=071.

Result FIX message:

  8=FIX.4.4.9=209.35=8.49=A0.56=I0.34=2.52=20010719-08:22:55.212=66.213=<?xml version="1.0" encoding="US-ASCII"?><out>Hello world!</out>.37=ORDER-1.17=0.150=0.32=0.31=0.0.39=0.55=ORCL.54=1.38=100.40=1.15=USD.151=0.14=0.6=0.0.10=149.