Previous Next JavaScript must be enabled to correctly display this content

## 15 Transformation Type

This topic provides the information about the transformation types.

Velocity

Velocity is a Java-based template engine. It is used to generate XML files, SQL, PostScript, and most other text-based formats.

Note:

In Routing Hub, velocity is used to generate JSON and XML files.

- Using $body, user can access request/response body.

  Syntax: $body.fieldName

  Example: $body.branchCode

- Using $headers, user can access request/response headers.

  Syntax: $headers["fieldName"][0]

  Example: $headers["branchCode"][0]

- Using $bodyAsString, user can access response body as string.

  Syntax: $bodyAsString

- Below are some available extension methods:
  - Date Conversion

    Syntax: $dateUtil.convert(inputDate, fromPattern, toPattern)

    Parameters:
    - inputDate - String
    - fromPattern - String
    - toPattern - String

    Returns: String

    Refer to https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for different patterns

  - Default Value

    Syntax: $custom.defaultValue(inputValue, defaultValue)

    Parameters:
    - inputValue - Object
    - defaultValue - String

    Returns: Object

  - Null Check

    Syntax: $custom.isNull(inputValue)

    Parameters:
    - inputValue - Object

    Returns: Boolean

  - Random Number

    Syntax: $mathUtil.getRandom()

    Returns: Object of Random class (java.util.Random)

  - Xml Tool

    Syntax: $xml.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/XmlTool.html

  - Date Tool

    Syntax: $date.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/DateTool.html

  - Json Tool

    Syntax: $json.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/JsonTool.html

  - Math Tool

    Syntax: $math.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/MathTool.html

  - Number Tool

    Syntax: $number.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/NumberTool.html

  - Escape Tool

    Syntax: $esc.methodName()

    Refer to https://velocity.apache.org/tools/3.1/apidocs/org/apache/velocity/tools/generic/EscapeTool.html

  - Serialization of object into its equivalent Json representation

    Syntax: $custom.toJson(src)

    Parameters:
    - src - Object

    Returns: String

  - Get additional field's value based on fieldname

    Syntax: $custom.getFieldValueById(jsonString, fieldname)

    Parameters:
    - jsonString – String
    - fieldname - String

    Returns: String

  - Get list of additional fields based on fieldname prefix

    Syntax: $custom.getAdditionalFieldSetByType(jsonString,prefixval)

    Parameters:
    - jsonString - String
    - prefixval - String

    Returns: String

  - This method is for parsing XML string

    Syntax: $custom.parseXml(xmlString)

    Parameters:
    - xmlString - String

    Returns: Object

- If issue occurred with hyphen in velocity template of Request or Response Transformation, then use get method.

  Example:

      <FCUBS_BODY>
         <Customer-IO>
           <CUSTNO>003942</CUSTNO>
         </Customer-IO>
      </FCUBS_BODY>

  If `$in.FCUBS_BODY.Customer-IO.CUSTNO` does not work , use `$in.FCUBS_BODY.get("Customer-IO").CUSTNO` to get customer number.

XSLT

XSLT is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL formatting objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

Note:

In Routing Hub, XSLT is used to transform arbitrary XML to JSON.

JSLT

JSLT is a complete query and transformation language for JSON.