Skip to main content
Skip table of contents

Create your own mapping helper class

To create your own codelibrary with a list of methods you can easily access from xslt in Link this is the way to do it.

First you need to create a custom class library in .Net with the methods you wish to have easy accessible in XSLT.

This could be simple c# methods but it could also be more complex methods that access additional data from your internal systems using API access. Maybe you need to extract the quantity on stock of a given item or fetch additional customer data from CRM or other system.

The code for that could look like this:

CODE
using System.Text.RegularExpressions;

namespace Bizbrains.Link.Sample
{
    public class MappingHelper
    {

        public static String NewGuid()
        {
            return Guid.NewGuid().ToString();
        }

        public static string RegexReplace(string input, string regex, string replacement)
        {
            return Regex.Replace(input, regex, replacement);
        }

        public static string StringSplit(string input, string separator, string index)
        {
            int i;
            if (!Int32.TryParse(index, out i))
            {
                return "";
            }
            string[] split = input.Split(separator);
            if (i >= split.Length)
            {
                return "";
            }
            return split[i];
        }
    }
}

When build to a dll you can upload it to Link artifact store.

image-20240827-133718.png

The class is then assigned to a namespace in the XslTransform itinerary step like this:

image-20240827-134122.png

And all the methods could then be accessible from XSLT by reffering to this namespace with a prefix and access the methods from xslt with that prefix like e.g

CODE
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:myHelper="https://Bizbrains.Link.Sample.MappingHelper" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl s0 myHelper" version="1.0" xmlns:s0="http://XsltProxyTest.Input" xmlns:ns0="http://XsltProxyTest.Output">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/>
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:Root"/>
  </xsl:template>
  <xsl:template match="/s0:Root">
    <ns0:Root>
        <MyNewGuid>
          <xsl:value-of select="myHelper:NewGuid"/>
        </MyNewGuid>
    </ns0:Root>
  </xsl:template>
</xsl:stylesheet>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.