how to write a xsl function in Biztalk custom xslt? Biztalk support xsl version 1.0, so many of the functions are not available. So how to write a function in my custom xslt to add a month in date field? RRS feed

All replies

  • What have you done so far?

    Why exclude C# scripts or static helper classes both are legit solutions and widely used if you are coding for the an msxml parser

    An XSL function is basically a template either called by a name or through a match to an xpath

    First you need to split the date into it's elements eg year, month, date
    Add 30 days and check the "overflow" compared to current month, increase month and set the day to the overflow

    The code gets huge and ugly 


    EDIT: Example in the second link: Date is converted to Julian Date format, days are added and then converted back to the Gregorian format
    JDN: Julian Date Numeric
    GD: Gregorian Date


    Saturday, June 2, 2018 10:27 AM
  • Eaxample with C# script




        <h2>AddDays example C# script</h2>


    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl=""
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl userCSharp"
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
    			<xsl:variable name="projectedDate">
    				<xsl:value-of select="Main/IssueDate"/>
    			<xsl:element name="html">
    				<xsl:element name="body">
    					<xsl:element name="h2">
    						<xsl:text>AddDays example C# script</xsl:text>
    					<xsl:element name="p">
    						<xsl:value-of select="userCSharp:DateAddDays($projectedDate, 30)"/>
    	<msxsl:script language="C#" implements-prefix="userCSharp">
    //  --------------------------------------------------------------------
    // Add number of dates to given date
    // Returns an empty string if given date parameter is not valid // -------------------------------------------------------------------- public string DateAddDays(string date, double daysToAdd) { DateTime validDate; IFormatProvider provider = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat; if (System.DateTime.TryParse(date, provider, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out validDate)) { validDate = validDate.AddDays(daystoAdd); return validDate.ToString("yyyy-MM-dd"); } return ""; } ]]> </msxsl:script> </xsl:stylesheet>

    Saturday, June 2, 2018 2:30 PM