XSLT Overview
XSLT (Extensible Stylesheet Language) is an XML-based language used for the transformation of XML documents to other formats. Using XSLT, OIPA transforms the inbound payload of the SOAP message into AsXml, which can then be transformed into objects and processed by the system.
OIPA adheres to XSLT Version 2 specifications, which allows for very flexible configuration of the transformation process. Standard XSLT elements can be used to transform the inbound message into AsXml based on templates, as well as to perform data validation and error handling.
All attributes that are used in the XSLT stylesheet must be defined either in the AsFile's XmlData column or in the Web Service's XML parameter. This is explained in the XSLT section.
Using Attributes from the XMLData Element of AsFile Entry
Each attribute defined in the XMLData section that will be needed in the XSLT stylesheet must first be declared as a parameter in the XSLT, after the XSLT prolog, using the <xsl:param> tag.
For example, PolicyGuid, set in the XMLData section, can be referenced in the XSLT by declaring it in the beginning of the XSLT like this:
<xsl:param name="PolicyGuid"></xsl:param> And then using it like this: <xsl:element name="PolicyGuid"> <xsl:value-of select="$PolicyGuid"></xsl:value-of> </xsl:element> |
Functions
Several functions are available for use inside of the XSLT stylesheet. They allow for added functionally, such as generating GUIDs and retrieving the current system time. The available utility functions are:
- getNextGUID()
- getGmtTimeString()
- formatDateTime()
- addMillis()
In order to use these added functions, the XsltFunctionHelper class must be added as a namespace in the XSLT prolog as noted below.
xmlns:utl="com.adminserver.webservice.helper.XsltFunctionHelper"
The getNextGUID() function will generate a new GUID. For example, the following code will output a newly generated GUID inside the <PolicyGuid> element.
<xsl:element name="PolicyGuid"> <xsl:value-of select="utl:getNextGUID()"/> </xsl:element> Functions can also be used to retrieve current system time and then format it properly for insertion into the database. <xsl:template name="GMT"> <xsl:param name="Offset" select="0" as="xs:integer"/> <xsl:value-of select="utl:formatDateTime(utl:addMillis (utl:getGmtTimeString (), $Offset))"/> </xsl:template> |
Validation and Error Handling
AsFile has the ability to perform data validations using the XSLT portion of the configuration. For example, the value of a variable can be tested to ensure the value is as expected.
The following validation syntax can be used anywhere in the XSLT:
<xsl:if test="$variable = 'incorrect value'"> <xsl:variable name="Error1" select="Error Message"/> <ValidationError ERRORSTATUSCODE="Err001"> <xsl:value-of select="$Error1 "/> </ValidationError> </xsl:if> |
If upon evaluation the <xsl:if> expression is true, then the <ValidationError> block will be executed. As a result, a SOAP fault will be thrown, and the text within the element, ERRORSTATUSCODE and resulting XML will be returned to the caller.
Transformation Examples
Example:1
XML Portion of SOAP Request
<NewPolicy> <PolicyName>TestPolicy</PolicyName> </NewPolicy> |
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:helper="com.adminserver.webservice.helper.XsltFunctionHelper" extension-element-prefixes="helper" version="2.0"> <xsl:param name="SystemDate"/> <xsl:template match="NewPolicy"> <xsl:element name="AsXml"> <xsl:variable name="PolicyName" select="./PolicyName"/> <xsl:element name="AsPolicy"> <xsl:element name="PolicyName"> <xsl:value-of select="PolicyName"/> </xsl:element> </xsl:element> </xsl:element> </xsl:template> </xsl:stylesheet> |
Resulting AsXml After Transformation:
<AsXml> <AsPolicy> <PolicyName>TestPolicy</PolicyName> </AsPolicy> </AsXml> |
Example 2
The following example shows the construction of the AsPolicy database table.
<xsl:template match="TXLife"> <xsl:element name="AsXml"> <!-- Create the AsPolicy Record --> <xsl:comment>Policy Info</xsl:comment> <xsl:element name="AsPolicy"> <xsl:element name="PolicyGuid"> <xsl:value-of select="$PolicyGUID"/> </xsl:element> <xsl:element name="StatusCode"> <xsl:text>08</xsl:text> </xsl:element> <xsl:element name="IssueStateCode"> <xsl:value-of select="$StateCode"/> </xsl:element> <xsl:element name="PolicyNumber"> <xsl:value-of select="$PolicyNumber"/> </xsl:element> <xsl:element name="PlanDate"> <xsl:value-of select="$PlanDate"/> </xsl:element> <xsl:element name="PlanGuid"> <xsl:value-of select="$PlanGUID"/> </xsl:element> <xsl:element name="CompanyGuid"> <xsl:value-of select="$CompanyGUID"/> </xsl:element> <xsl:element name="UpdatedGMT"> <xsl:value-of select="$UpdatedGMT"/> </xsl:element> <xsl:element name="CreationDate"> <xsl:value-of select="$CreationDate"/> </xsl:element> </xsl:element> </xsl:element> </xsl:template> |