Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Transaction Pipeline Processing : XSLT Functions for URL Encode and URL Decode

XSLT Functions for URL Encode and URL Decode
To encode or decode any special characters in the headers or the payload body of the request message, TIBCO API Exchange Gateway provides the following XSLT functions to be used in the XSLT file:
The namespace for the above functions is as follows:
http://www.tibco.com/asg/functions/url
Decode() Function
The decode function decodes any URL-encoded characters in the input string passed as an argument.
For example, if a string contains the %20 character , the decode () function decodes it to the space character.
In the following example, Single%20general%20admission is converted as Single general admission.
Sample XSLT (Decode)
The following is the sample XSLT for the decode function, which decodes any URL-encoded characters in the <payload> element of request message.
In the following example, the description field is defined as Single%20general%20admission%20theater%20ticket. The decode() function transforms the value of description field as Single general admission theater ticket.

 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:url="http://www.tibco.com/asg/content-types/url"
xmlns:f="http://www.tibco.com/asg/functions/url"
exclude-result-prefixes="xsl f">
<xsl:output indent="yes" method="xml" />
<xsl:template match="/">
<context>
<entry name="request">
<http>
<payload>
<xsl:copy-of
select="f:decode(context/entry[@name='request']/http/payload)" />
</payload>
</http>
</entry>
</context>
</xsl:template>
</xsl:stylesheet>

 
Sample Input XML(Decode)
The following is the sample input XML for the decode function:

 
<?xml version="1.0" encoding="UTF-8"?>
<context>
<entry name="request">
<http>
<payload>endUserId=acr:Authorization&amp;transactionOperationStatus=charged&amp;description=Single%20general%20admission%20theater%20ticket&amp;code=wac-11faf3e6-e440-4daa-824e-62d8ed83723e&amp;referenceCode=REF-ASM600-239238&amp;onBehalfOf=WAC%20Cinemas%20Inc&amp;purchaseCategoryCode=Ticket&amp;channel=WAP
</payload>
</http>
</entry>
</context>

 
Sample Output XML(Decode)
The following is the sample output XML from the decode function:

 
<?xml version="1.0" encoding="UTF-8"?>
<context xmlns:url="http://www.tibco.com/asg/content-types/url">
<entry name="request">
<http>
<payload>
<url xmlns="http://www.tibco.com/asg/content-types/url">endUserId=acr:Authorization&amp;transactionOperationStatus=charged&amp;description=Single general admission theater ticket&amp;code=wac-11faf3e6-e440-4daa-824e-62d8ed83723e&amp;referenceCode=REF-ASM600-239238&amp;onBehalfOf=WAC Cinemas Inc&amp;purchaseCategoryCode=Ticket&amp;channel=WAP
</url>
</payload>
</http>
</entry>
</context>

 
Encode() Function
The encode() function encodes the special characters in the input string to the URL-encoded characters.
For example, if a string contains the backspace character , the encode () function encodes it to the %08 character.
Sample XSLT (Encode)
The following is the sample XSLT for the encode function, which encodes the special characters in the <payload> element of request message to the URL- encoded characters.
In the following example, the description field is defined as Single general admission theater ticket. The encode() function transforms the value of description field as Single%20general%20admission%20theater%20ticket.

 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:url="http://www.tibco.com/asg/content-types/url"
xmlns:f="http://www.tibco.com/asg/functions/url"
exclude-result-prefixes="xsl f">
<xsl:output indent="yes" method="xml" />
<xsl:template match="/">
<context>
<entry name="request">
<http>
<payload>
<xsl:copy-of
select="f:encode(context/entry[@name='request']/http/payload)" />
</payload>
</http>
</entry>
</context>
</xsl:template>
</xsl:stylesheet>

 
Sample Input XML(Encode)
The following is the sample input XML for encode function:

 
<?xml version="1.0" encoding="UTF-8"?>
<context xmlns:url="http://www.tibco.com/asg/content-types/url">
<entry name="request">
<http>
<payload>endUserId=acr:Authorization&amp;transactionOperationStatus=charged&amp;description=Single general admission theater ticket&amp;code=wac-11faf3e6-e440-4daa-824e-62d8ed83723e&amp;referenceCode=REF-ASM600-239238&amp;onBehalfOf=WAC Cinemas Inc&amp;purchaseCategoryCode=Ticket&amp;channel=WAP
</payload>
</http>
</entry>
</context>

 
Sample Output XML(Encode)
The following is the sample output XML from the encode function:

 
<?xml version="1.0" encoding="UTF-8"?>
<context>
<entry name="request">
<http>
<payload>endUserId=acr:Authorization%26amp;transactionOperationStatus=charged%26amp;description=Single%20general%20admission%20theater%20ticket%26amp;code=wac-11faf3e6-e440-4daa-824e-62d8ed83723e%26amp;referenceCode=REF-ASM600-239238%26amp;onBehalfOf=WAC%20Cinemas%20Inc%26amp;purchaseCategoryCode=Ticket%26amp;channel=WAP
</payload>
</http>
</entry>
</context>

 
How to Use Encode() and Decode() Functions
To use the encode() and decode() XSLT functions, follow these steps:
 
Task A Create an XSLT File
Create an XSLT file with decode() and encode() functions, as required. Refer to the following XSLT files to create an XSLT file:
Task B Upload the XSLT File
To upload the XSLT file for a facade operation, follow these steps:
1.
2.
3.
4.
On the ROUTING tab, click Routing on the top menu.
5.
Select the Facade Operations tab.
6.
In the New ProcessBody Transform field, upload the XSLT file.
7.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved