Knowledgebase

Article number: 301412

Special characters in XML Data Island Hyperlinks

This article explains how to pass special characters, such as ampersand, in hyperlinks from XML data islands via HTTP GET using XSL and EXSL.

Often it is necessary to transfer parameters from an XML Data Island on one page, to another page but this can cause problems where the value being transferred contains special characters such as ampersand (&).

When a parameters are passed using HTTP GET the parameters are appended to the URL of the requested page using ampersands as delimiters. For example,

"http://www.test.com?is=12345&companyname=hinge & sprocket" causes problems because 'sprocket' is treated as a separate parameter, instead of the value of the companyname parameter.

The solution is to use EXSL extensions to XSL 1.0 and use EXSLT XML data islands on your sitekit pages.

EXSL provides a function 'str:encode-uri', which can be used to encode values into a form suitable for transfer via HTTP GET. This code snipnet gives an example of how to use it:

XML:
<companys>
<company>hinge & sprocket</company>
<company>Sharp# Suits</company>
</companys>

EXSL Snippet:
<xsl:template select="//company">
<a href="http://www.test.com?companyname={str:encode-uri(.,true())}"><xsl:value-of select="company"></a>
</xsl:template>

Related questions