Generating Menus Dynamically with XSL

The PT application presents menus dynamically depending on the role of the user who is logging on. The PT Admin application generates only a single menu, because by definition, all its users are administrators. The PT User application presents different menus to individuals, evaluators, and auditors.

The PT application accomplishes this task using an XSL file. The ASP file (menu.asp) that generates the menu frame for the application performs an XSL transformation on an XML file that contains all the possible options that users in each role can select from application menus.

Code in menu.asp causes menu.xsl to iterate through the data—in this case, the names of forms, tables, and actions—to mark it up as HTML for display. When the HTML page that implements the menus has been generated, menu.asp returns it to the browser.

The following diagram illustrates the XSL transformation that generates the PT application's menus. The application loads menu.xsl and menu.xml into separate XML document objects. Code in menu.xsl processes menu.xml. The HTML that results implements the application's menus.

The HTML returned by the XSL transformation that generates the PT application's menus includes the Internet Explorer Popup ActiveX® control embedded in an <OBJECT> tag. The control accepts values contained in <PARAM> tags. These values are names of the menus and menu options. Rather than hard-coding menu names as VALUE attributes in the <PARAM> tags, the XSL transformation passes these values from the menu.xml file to the menu.xsl file where the logic inserts them into the Popup control as arguments to the control's methods and events.

Unlike the XML merge used to create the rest of the user interface, the XSL transformation that creates application menus never results in persistent HTML files. The application creates the menus dynamically in response to each request for a form or table.

Implementing the Menu Bar describes how the LitWare development team implemented this feature.