Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:func="http://link/xslt" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl s0 func" version="1.0" xmlns:s0="http://XsltFunctionsTest.Input" xmlns:ns0="http://XsltFunctionsTest.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>


      <Document>
        <DocumentType>
          <xsl:value-of select="func:GetDocumentTypeName()"/>
        </DocumentType>
        <MessageNumberIn>
          <xsl:value-of select="func:GetDocumentMessageNumberIn()"/>
        </MessageNumberIn>
        <MessageNumberOut>
          <xsl:value-of select="func:GetDocumentMessageNumberOut()"/>
        </MessageNumberOut>
        <DocumentNumber>
          <xsl:value-of select="func:GetDocumentNumber()"/>
        </DocumentNumber>
      </Document>

      <DocumentConfigIn>
        <Format>
          <xsl:value-of select="func:GetDocumentFormatIn()"/>
        </Format>
        <Variant>
          <xsl:value-of select="func:GetDocumentVariantIn()"/>
        </Variant>
        <Version>
          <xsl:value-of select="func:GetDocumentVariantVersionIn()"/>
        </Version>
      </DocumentConfigIn>

      <DocumentConfigOut>
        <Format>
          <xsl:value-of select="func:GetDocumentFormatOut()"/>
        </Format>
        <Variant>
          <xsl:value-of select="func:GetDocumentVariantOut()"/>
        </Variant>
        <Version>
          <xsl:value-of select="func:GetDocumentVariantVersionOut()"/>
        </Version>
      </DocumentConfigOut>

      <Distribution>
        <ConfigurationKeys>
          <UNBOverride>
            <xsl:value-of select="func:LookupDistributionConfigurationKey('UNBOverride')"/>
          </UNBOverride>
        </ConfigurationKeys>
      </Distribution>

      <InterchangeIn>
        <InterchangeNumber>
          <xsl:value-of select="func:GetInterchangeInNumber()"/>
        </InterchangeNumber>
        <InterchangeGuid>
          <xsl:value-of select="func:GetInterchangeInInterchangeGuid()"/>
        </InterchangeGuid>
        <TransmissionId>
          <xsl:value-of select="func:GetInterchangeInTransmissionId()"/>
        </TransmissionId>
        <DisplayAddress>
          <xsl:value-of select="func:GetInterchangeInDisplayAddress()"/>
        </DisplayAddress>
        <PortName>
          <xsl:value-of select="func:GetInterchangeInPortName()"/>
        </PortName>
        <FormatType>
          <xsl:value-of select="func:GetInterchangeInFormatType()"/>
        </FormatType>
      </InterchangeIn>

      <PartnerIn>
        <Name>
          <xsl:value-of select="func:GetPartnerInName()"/>
        </Name>
        <PartnerKey>
          <xsl:value-of select="func:GetPartnerInPartnerKey()"/>
        </PartnerKey>
        <Comment>
          <xsl:value-of select="func:GetPartnerInComment()"/>
        </Comment>
        <IsInternal>
          <xsl:value-of select="func:GetPartnerInIsInternal()"/>
        </IsInternal>
        <IsDeleted>
          <xsl:value-of select="func:GetPartnerInIsDeleted()"/>
        </IsDeleted>
        <MainId>
          <xsl:value-of select="func:GetPartnerInMainId()"/>
        </MainId>
        <GLN>
          <xsl:value-of select="func:LookupPartnerInIdByKey('GLN')"/>
        </GLN>
        <VendorNumber>
          <xsl:value-of select="func:LookupPartnerInConfigurationKey('VendorNumber')"/>
        </VendorNumber>
      </PartnerIn>

      <PartnerOut>
        <Name>
          <xsl:value-of select="func:GetPartnerOutName()"/>
        </Name>
        <PartnerKey>
          <xsl:value-of select="func:GetPartnerOutPartnerKey()"/>
        </PartnerKey>
        <Comment>
          <xsl:value-of select="func:GetPartnerOutComment()"/>
        </Comment>
        <IsInternal>
          <xsl:value-of select="func:GetPartnerOutIsInternal()"/>
        </IsInternal>
        <IsDeleted>
          <xsl:value-of select="func:GetPartnerOutIsDeleted()"/>
        </IsDeleted>
        <MainId>
          <xsl:value-of select="func:GetPartnerOutMainId()"/>
        </MainId>
        <CVR>
          <xsl:value-of select="func:LookupPartnerOutIdByKey('CVR')"/>
        </CVR>
        <CustomerNumber>
          <xsl:value-of select="func:LookupPartnerOutConfigurationKey('CustomerNumber')"/>
        </CustomerNumber>
      </PartnerOut>

      <ConversionTables>
        <Lookup1>
          <xsl:value-of select="func:ConversionLookupGlobalValue('Table1', 'LookupColumn1', 'Column1', 'Column1Value')"/>
        </Lookup1>
        <Lookup2>
          <xsl:value-of select="func:ConversionLookupPartnerInValue('Table2', 'LookupColumn2', 'Column1', 'Column1Value', 'Column2', 'Column2Value')"/>
        </Lookup2>
        <Lookup3>
          <xsl:value-of select="func:ConversionLookupPartnerOutValue('Table3', 'LookupColumn3', 'Column1', 'Column1Value', 'Column2', 'Column2Value', 'Column3', 'Column3Value')"/>
        </Lookup3>
      </ConversionTables>

      <LinkSettings>
        <Setting1>
          <xsl:value-of select="func:GetSettingValue('Setting1')"/>
        </Setting1>
      </LinkSettings>

      <ErrorHandling>
        <FailDocument>
          <xsl:value-of select="func:RaiseError('No lines found in order.', false())"/>
        </FailDocument>
        <FailDocumentWithErrorCode>
          <xsl:value-of select="func:RaiseError('No lines found in order.', 'RT62W', false())"/>
        </FailDocumentWithErrorCode>
        <IgnoreDocument>
          <xsl:value-of select="func:RaiseError('No lines found in order.', 'RT62W', 'Ignored', false())"/>
        </IgnoreDocument>
      </ErrorHandling>

      <ContextProperties>
        <TestProperty>
          <xsl:value-of select="func:GetContextPropertyValue('NoPropertySomeProperty', 'http://schemas.bizbrains.com/properties/test')"/>
        </TestProperty>
      </ContextProperties>

      <xsl:variable name="test" select="func:SetContextPropertyValue('SomeProperty', 'http://schemas.bizbrains.com/properties/test', 'SomeValue')" />

    </ns0:Root>
  </xsl:template>
</xsl:stylesheet>
Info

The same example is available in the Visual Studio project template where it’s possible to debug into the XSLT.

...

These are the methods for doing lookups in conversion tables.

ConversionLookup[LookupType]Value(string conversiontablename, string returncolumn, string searchcolumn[N], string searchvalue[N], …, string suppressExceptions)

This is a template for the methods used for performing a conversion table lookup.

...

Each of the three lookup types support between 1 and 5 pairs of search columns and search values.

Link settings

Should you have a need for it, you can get the value of any Link setting on the system.

GetSettingValue(string key)

Returns the value of the setting.

Error handling

These are the methods used for error handling.

RaiseError(string message, bool retryAllowed)

This method is used for making a document intentionally go into Failed status in Link.

There can be many reasons for wanting to do this. Say for instance that you know that you sometimes get an order where one of the lines is missing the EAN number of the product. You also know that this will make the order impossible to process in your system. You may prefer in this situation to have the order fail in Link with a clear error message stating exactly why it failed, rather than having it sent on to your system and have to deal with it there.

In that case you can check the existence of the EAN number in the XSLT, and if it is missing you can call this method with a message saying that the EAN number is missing.

The retryAllowed parameter should always be set to false except in very specific cases. Any error that stems from faulty input data will not be resolved by trying to map the faulty data again.

RaiseError(string message, string errorCode, bool retryAllowed)

This method is the same as above, but allows you to register the error with a specific error code. If you have a known error scenario that you know a specific department needs to take care of, you can register the error code in Link and assign a specific stakeholder to it. Then any time a document fails with that specific error code, the stakeholder will be notified.

RaiseError(string message, string errorCode, string documentStatus, bool retryAllowed)

This method is the same as above, but allows you to set a specific document status rather than defaulting to “Failed”.

The practical use for this is making a document intentionally go into Ignored status in Link.

There can be many reasons for wanting to do this. Say for instance that you know that you sometimes get an order with no lines. You know that this happens due to an error in some customer’s system from time to time, and does not need any action from your side. Rather than having the faulty but unimportant order sent on to your system, it may be better to simply halt the processing of it in Link, and put a message on it saying why it has been ignored.

Context Properties

If your XSLT is being executed within Link, you can access the context properties of the message from the proxy class.

GetContextPropertyValue(string propertyName, string propertyNamespace)

This method returns the value of the given context property from the message, or an empty string if the property does not exist.

SetContextPropertyValue(string propertyName, string propertyNamespace, string value)

This method writes a value to the message context.

Data manipulation

The proxy library also contains a few methods that do not extract any data from Link, but which can be useful in various mapping scenarios.

ConvertDate(string dateToConvert, string inputFormat, string outputFormat)

This method converts a date(time) from one format to another. The two format parameters use the standard .NET DateTime formatstring format.

ReturnNumberFormat(string number, string formatMask)

This method formats a number using a standard .NET number format mask.

Replace(string value, string replaceFrom, string replaceTo)

...

string suppressExceptions

This parameter is optional. If it is not used in a call, the lookup method will never fail, it will simply return an empty string if anything goes wrong, such as the conversion table not existing, or one of the lookup values being blank. If you explicitly want the map to fail in one of those situations, add the parameter to the end of the call as false() or ‘false’.

While the parameter is logically a boolean value, it is implemented as a string to make it “play nice” with XSLT.

Link settings

Should you have a need for it, you can get the value of any Link setting on the system.

GetSettingValue(string key)

Returns the value of the setting.

Error handling

These are the methods used for error handling.

RaiseError(string message, string retryAllowed)

This method is used for making a document intentionally go into Failed status in Link.

There can be many reasons for wanting to do this. Say for instance that you know that you sometimes get an order where one of the lines is missing the EAN number of the product. You also know that this will make the order impossible to process in your system. You may prefer in this situation to have the order fail in Link with a clear error message stating exactly why it failed, rather than having it sent on to your system and have to deal with it there.

In that case you can check the existence of the EAN number in the XSLT, and if it is missing you can call this method with a message saying that the EAN number is missing.

The retryAllowed parameter should always be set to false() or ‘false’ except in very specific cases. Any error that stems from faulty input data will not be resolved by trying to map the faulty data again. While the parameter is logically a boolean value, it is implemented as a string to make it “play nice” with XSLT.

RaiseError(string message, string errorCode, string retryAllowed)

This method is the same as above, but allows you to register the error with a specific error code. If you have a known error scenario that you know a specific department needs to take care of, you can register the error code in Link and assign a specific stakeholder to it. Then any time a document fails with that specific error code, the stakeholder will be notified.

RaiseError(string message, string errorCode, string documentStatus, string retryAllowed)

This method is the same as above, but allows you to set a specific document status rather than defaulting to “Failed”.

The practical use for this is making a document intentionally go into Ignored status in Link.

There can be many reasons for wanting to do this. Say for instance that you know that you sometimes get an order with no lines. You know that this happens due to an error in some customer’s system from time to time, and does not need any action from your side. Rather than having the faulty but unimportant order sent on to your system, it may be better to simply halt the processing of it in Link, and put a message on it saying why it has been ignored.

Context Properties

If your XSLT is being executed within Link, you can access the context properties of the message from the extension object.

GetContextPropertyValue(string propertyName, string propertyNamespace)

This method returns the value of the given context property from the message, or an empty string if the property does not exist.

SetContextPropertyValue(string propertyName, string propertyNamespace, string value)

This method writes a value to the message context.

Utility functions

The extension object also contains a few methods that do not extract any data from Link, but which can be useful in various mapping scenarios.

ConvertDate(string dateToConvert, string inputFormat, string outputFormat)

This method converts a date(time) from one format to another. The two format parameters use the standard .NET DateTime formatstring format.

ReturnNumberFormat(string number, string formatMask)

This method formats a number using a standard .NET number format mask.

Replace(string value, string replaceFrom, string replaceTo)

This method performs a string replace operation on value, replacing all instances of replaceFrom with replaceTo.

DateAdd(string dateTime, string format, string days, string months, string years)

Takes an input date and time string, which must be in the specified format, adds the given number of days, months, and years to it, and returns the resulting date and time formatted according to the same format.

TimeAdd(string dateTime, string format, string hours, string minutes)

Takes an input date and time string, which must be in the specified format, adds the given number of hours, and minutes to it, and returns the resulting date and time formatted according to the same format.

GetLocalDateTime()

Gets the current local date and time formatted according to the standard XML date and time format mask.

GetLocalDateTime(string formatMask)

Gets the current local date and time formatted according to the specified format mask.

GetUtcDateTime()

Gets the current UTC date and time formatted according to the standard XML date and time format mask.

GetUtcDateTime(string formatMask)

Gets the current UTC date and time formatted according to the specified format mask.

MathRound(string number, string decimals)

Round the given number to the specified number of decimal places using away-from-zero rounding.

RegexReplace(string input, string pattern, string replacement)

Apply the given regular expression pattern to substitute parts of the input string with the specified replacement string.

SplitString(string input, string separator, string index)

Divide the input string into segments using the given separator string and return the segment at the specified index (starting from 0). If no segment matches the index, an empty string is returned.

ToUpper(string input)

Transform the entire input string to uppercase.

ToLower(string input)

Transform the entire input string to lowercase.