This topic discusses the PT application's decode function, which wraps the native JavaScript unescape function.
The PT Admin application stores user interface text elements as Unicode values in XML files. This ensures that text appears correctly regardless of the type of browser requesting an application screen. A common deployment scenario for this application is for a system administrator to set up the application for an application administrator. The system administrator who sets up the application builds the localized HTML pages by selecting options from the Build menu. The application includes a set of HTML pages in a default language that might not be the same as the language of the PT application administrator's browser. (If a set of HTML files that match the browser's locale have already been built, they will appear in that language.) Storing the PT application's user interface strings in Unicode ensures they appear correctly in a browser set for a different language preference, which means the system administrator can build a set of application pages that are appropriately localized.
Note This topic discusses the decode function, which wraps the native JavaScript unescape function. The BackOffice Developer's Guide also provides a Decode function written in VBScript for Hello World XML. This function is necessary because VBScript does not have an equivalent to the unescape function.
The process that builds the menu handles the conversion from Unicode to character data with a global function at the end of the menu.xsl file. To understand this function, recall one of the places the XSL file uses it:
<xsl:attribute name="ONCLICK">topNavigator<xsl:eval>childNumber(this)-1</xsl:eval>.PopUp()</xsl:attribute>
<xsl:eval>decode(this,'l_name')</xsl:eval>
The preceding code uses the childNumber method of the XML document object. Its parameter is a reference to the object for which the childNumber is returned. This object reference is then passed to the decode function, which loads the reference into the object variable me and into the l_name attribute of the node. The l_name attribute ultimately becomes a text string that is visible in the user interface. The decode function then calls the JavaScript unescape function. The unescape function provides decoding functionality that replaces characters encoded in %uxxxx format (URL encoded characters) with their Unicode equivalents in hexadecimal encoding xxxx format, which the browser can interpret as character data. The following code illustrates the decode function:
<!--GLOBAL SCRIPT FUNCTION USED WHILE TRANSFORMING DATA-->
<xsl:script language="javascript"><![CDATA[
var getrootNode;
function decode(me,attrib){
return unescape(me.getAttribute(attrib));
}
function getNode(me,str){
getrootNode = decode(me,str);
}
]]></xsl:script>
The unescape function takes a string in Unicode format and returns a string with hexadecimal encoding that is interpreted as character data. Here, the string that is passed results from the evaluation of the expression me.getAttribute(attrib). This expression evaluates to the name of the item (menu name or menu item) that appears in the menu bar or Popup control.
Note It is recommended that you mark the XSL script blocks as character data (CDATA) as in the preceding example. This prevents stray brackets (< or >) from causing parsing errors and automatically preserves white space. If white space is not preserved, single-line comments such as // in JavaScript might lose their terminating return, causing undesirable results.