Tech Blog

Understanding the BizTalk Mapper: Part 8 – Scientific Functoids

Yet another category which has no direct support in XSLT v1.0 or XSLT v2.0!
However, given the strong support for scientific functions in .NET, it’s easy to call
out to .NET classes, which is exactly what every single one of the functoids in this
category does.

Having said that: have you ever used one of these functoids in a map? Care to share
a real world example?
I’d be interested to find out how often they are used.

For each functoid I’ve shown:

  1. Whether XSLT or C# is emitted
  2. Whether an XSLT equivalent exists
  3. The XSLT or C# emitted by the functoid
  4. Where C# is emitted, the equivalent XSLT to achieve the same functionality (in both
    XSLT v1.0 and v2.0)

Functoids covered in this category:

10^n Natural Logarithm
Arc Tangent Sine
Base-Specified Logarithm Tangent
Common Logarithm X^Y
Cosine Common Code
Natural Exponential Function  

Note:

This is the eighth in a series of 13 posts about the BizTalk Mapper.
The other posts in this series are (links will become active as the posts become active):
Understanding
the BizTalk Mapper: Part 1 – Introduction


Understanding
the BizTalk Mapper: Part 2 – Functoids Overview


Understanding
the BizTalk Mapper: Part 3 – String Functoids


Understanding
the BizTalk Mapper: Part 4 – Mathematical Functoids


Understanding
the BizTalk Mapper: Part 5 – Logical Functoids


Understanding
the BizTalk Mapper: Part 6 – Date/Time Functoids


Understanding
the BizTalk Mapper: Part 7 – Conversion Functoids


Understanding the BizTalk Mapper: Part 8 – Scientific Functoids

Understanding the BizTalk Mapper: Part 9 – Cumulative Functoids>

Understanding
the BizTalk Mapper: Part 10 – Database Functoids


Understanding
the BizTalk Mapper: Part 11 – Advanced Functoids


Understanding
the BizTalk Mapper: Part 12 – Performance and Maintainability


Understanding
the BizTalk Mapper: Part 13 – Is the Mapper the best choice for Transformation in
BizTalk?

Download the complete series as a single Microsoft
Word document (1.2MB)
or Adobe
PDF document (620kb)
.

Scientific Functoids

Note: XSLT has no intrinsic trigonometric functions, although you can
download open source libraries such as FXSL

 

10^n

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciExp10(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Pow(10.0, dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Arc Tangent

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciArcTan(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Atan(dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Base-Specified
Logarithm

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciLogn(string val1, string val2)

{

    string retval
= “”;


    double dval1
= 0;


    double dval2
= 0;


    if (IsNumeric(val1, ref dval1)
&& IsNumeric(val2, ref dval2))


    {

        if (dval1
> 0 && dval2 > 0)


       
{


            double denom
= Math.Log(dval2);


            if (denom
!= 0)


           
{


                double ret
= Math.Log(dval1) / denom;


               
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


           
}


       
}


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Common Logarithm

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciLog10(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        if (dval
> 0)


       
{


            double ret
= Math.Log10(dval);


           
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


       
}


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Cosine

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciCos(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Cos(dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Natural Exponential
Function

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciExp(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Exp(dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Natural Logarithm

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciLog(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        if (dval
> 0)


       
{


            double ret
= Math.Log(dval);


           
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


       
}


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Sine

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciSin(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Sin(dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

Tangent

 

 

Generates: C#

Has XSLT Equivalent: No

  Emitted Code:

public string SciTan(string val)

{

    string retval
= “”;


    double dval
= 0;


    if (IsNumeric(val, ref dval))

    {

        double ret
= Math.Tan(dval);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}
 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 

 

X^Y

 

 

Generates: C#

Has XSLT Equivalent: No

 

Emitted Code:

public string SciPow(string val1, string val2)

{

    string retval
= “”;


    double dval1
= 0;


    double dval2
= 0;


    if (IsNumeric(val1, ref dval1)
&& IsNumeric(val2, ref dval2))


    {

        double ret
= Math.Pow(dval1, dval2);


       
retval = ret.ToString(System.Globalization.CultureInfo.InvariantCulture);


    }

    return retval;

}

 

XSLT 1.0 Equivalent: (none)

 

XSLT 2.0 Equivalent: (none)

 
  Common Code

(this is common code used by all the scientific functoids)
  public bool IsNumeric(string val)

{

    if (val
== null)


    {

        return false;

    }

    double d
= 0;


    return Double.TryParse(val,
System.Globalization.NumberStyles.AllowThousands
| System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);


}

 

public bool IsNumeric(string val, ref double d)

{

    if (val
== null)


    {

        return false;

    }

    return Double.TryParse(val,
System.Globalization.NumberStyles.AllowThousands
| System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);


}

Back to Tech Blog