17
Wed, Apr
5 New Articles

XSL Style Sheets: Display Files of the Web

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

A little over a year ago, I created my first Web application to publish AS/400 data. The application was based on a three-tier architecture. In the first tier, a Web browser presented the data to the user. In the middle tier, Active Server Pages (ASPs), coupled with ASNA Visual RPG (AVR) components, implemented the business rules. In the third tier, an AS/400 was serving the data. The technologies involved were pretty easy to grasp. Besides learning the basic mechanics of Web serving, I had to learn a little HTML and how to create ActiveX components to interact with the ASP machinery.

Even though I could have created an ActiveX component or Java applet to deliver logic to the user, I opted against it for three reasons. First, users can be impatient and might not have waited for the component to download to their machines. Second, the application would have become dependent on the end user’s platform, especially in the case of an ActiveX program, and some users might have been marginalized. The third reason for avoiding this model was scalability. When a component is running on a browser and accessing data directly on the AS/400, the architecture being used is the traditional client/server, which, apart from increasing the security concerns, imposes huge demands on the AS/400. Each user navigating through the Web application would start at least one AS/400 job. Imagine the number of active jobs the machine would have to support at Web rush hour! For these reasons, I chose the three-tier model, which nicely addressed all of these issues.

Why Use XML?

Under the three-tier architecture, the middle tier accesses data from DB2/400, processes it, and produces HTML. The HTML is then sent to the browser which presents the data in its window. HTML is a format used to direct the browser on how to present the data.


However, developers producing HTML directly from within their applications end up “contaminating” the applications by inserting code for HTML alongside that of the applications’ business rules. They also end up with applications that are useful only when accessed from a Web browser. Modern Web applications should produce Extensible Markup Language (XML). (For an introduction to XML, please see my article “XML: The E-language for E-business” in the March 2000 issue of MC.)

To get an idea of how problematic it is to generate HTML from an application, imagine that, within your RPG or COBOL program, you had to deal with the details of the 5250 data stream used with dumb terminals. Your program would end up being very hard to maintain, and any changes to the appearance of the screen would imply code changes and program recompiles. In the case of Web applications, this problem is compounded because Web masters, usually hired by the marketing department, have strong opinions on how information should be presented to the user.

Separating Presentation from Data

On traditional AS/400 applications, you separate the data itself from the way the data is to be presented to the user. A display file serves as a template, which is merged with the data calculated by a program to form what the user sees on the screen. This merging happens when the program issues a write or an execute-format to the display file. The need to separate the presentation from the data becomes more demanding as the dynamism of the Web site grows. The trick to this separation is to output the data produced by the application in XML and then apply a transformation to it using some form of externally described format.

Extensible Stylesheet Language (XSL) is a language used to define style sheets; a style sheet contains templates indicating how to transform data from XML into HTML. XSL is a declarative language, not a procedural one. Conceptually, it is more like O-specs than C-specs. With XSL, a set of templates is built to process specific types of XML documents and transform them into HTML or even to create a new XML document with a different structure or format. When the HTML is needed, a processor (which I’ll describe in a moment) takes the templates in the style sheet and applies them to the document. This process is similar to doing a “mail merge” using a word processing program.

Like a Tree

A well-formed XML document can be described as a tree, with a single element as its root and multiple elements and subelements as the branches and leafs. The elements in the tree are known as nodes of the tree. At runtime, templates in the style sheet are matched with the nodes of the tree. When a match is made, the corresponding template is applied. This results in a transformation of the XML document into, for example, another XML document of a different type or into an HTML document. This transformation is done by an XSL processor, and it can occur either on the client side (if the user has a newer Web browser) or on the Web server itself.

When the process is done on the server, the programmer needs to call processor methods. XSL processors are also bundled with other Web products. Microsoft provides its processor as an ActiveX component, which is included with Internet Explorer 5.0; it is


accessible from languages such as Visual Basic (VB) and AVR. IBM makes the Lotus XSL processor, a set of Java classes that is available as part of WebSphere Application Server Version 3.

Formally, XSL is divided into two areas. One area deals with the selection of nodes, and the other area deals with the actual transformations. The World Wide Web Consortium (www.w3c.org) released the two standards defining these areas last November: XSL Transformations (XSLT) and XML Path Language (XPath).

A Closer Look at XSL

XSL uses XML as its syntax, which has several advantages. The main advantage is that, in general, the tools and technologies created for XML can be used for XSL immediately. Currently, programmers and Web masters have to create the style sheets by hand with text editors. However, the wave of WYSIWYG editors for style sheets is approaching the shore quickly. For now, though, having XSL use the XML syntax frees XML authors from having to learn another markup language.

Take a look at an example. Figure 1 (on page 57) shows an article listing in XML format. In the example, the element is the root. It contains two branch elements, and . The element has five subelements, all of them of type

. Each article subelement has four attributes, with the details pertaining to individual articles. Figure 2 (on page 57) shows a style sheet, written in XSL, with a single template to transform the list of articles into a displayable table. Figure 3 shows a browser displaying the result of the transformation.

The template matches the root node by indicating a slash (/) as the pattern to find. The content of the template is basically an HTML file with "holes" in it that are to be filled with data coming from the XML document. These holes are marked by the element , which outputs the actual value of the selected node. The node is selected by specifying its path from the root or whatever the current node might be. To access attributes of an element, prefix the attribute name with an "at" sign (@), like this: Catalog/Category/@ID.

To work with a list of similar nodes, such as the actual list of articles, use . This instruction will iterate over the list of selected nodes, applying whatever transformations are indicated within it. At every iteration, the selected node becomes the current node. References to elements and attributes of the node are done by using their names directly, like this: . The , coupled with and , is very similar to RPG's SELECT op code, allowing for conditional execution of the template sections.

XSL transforms the XML tree into a new tree, allowing extensive reordering, generated text, and calculations. This is in contrast to Cascading Style Sheets (CSS), which only "decorate" an XML tree with formatting properties. (See "XML and CSS: Displaying Information on the Web" in this issue by Teresa Pelkie.)

The XML source generation can be maintained by the programmer from the perspective of "pure content" and can be delivered simultaneously to different users by providing different style sheets. In my example, I could deliver basic catalog information, article ID, and quantity available to a palmtop device just by switching the style sheet!


And It's Just Getting Started

You can use style sheets to convert an XML document from one schema to another without having to write a program. This capability will become extremely useful as XML technology starts to encroach into the electronic data interchange (EDI) domain. And even though the current implementations of XSL-supporting products may differ from vendor to vendor, it is worthwhile getting a head start with the technology that will change the landscape of data processing by starting some pilot projects within your organization.

Editor's note: The XML and XSL files shown in Figures 1 and 2 are available for download from www.midrangecomputing.com/mc. Please realize, however, that the XML was dynamically generated by a server-side application program. That program can be written in any language, but this "nuts and bolts" application, in particular, generated its XML with AVR. The AVR application senses whether or not the browser is Internet Explorer 5.0. If the browser is Internet Explorer 5.0 or higher, the AVR application simply sends the XML and XSL files. But, if the browser is other than Internet Explorer 5.0, the AVR application transforms the XML into HTML (via the XSL rules) on the server with the following three lines of code:

TheData.LoadXml(XmlString)
TheStyleSheet.Load(“C:StylesheetsArticles.xsl”)
Response.Write(TheData.TransformNode(TheStyleSheet))


Eduardo C. Ross has been vice president and director of research and development at ASNA since 1987. He is responsible for the design of the companys new technology and jointly holds patents included in Acceler8DB. You can reach Eduardo via email at This email address is being protected from spambots. You need JavaScript enabled to view it.
.



Headed Bolts



http://www.w3.org/TR/WD-xsl">

Nuts and Bolts Articles


Articles for Category



ID Description Available Unit


Category Description:


Figure 1: This XML article listing will be transformed into HTML.

Figure 2: A single template in this XSL style sheet is used to transform the list of articles into a displayable HTML table.


XSL_Style_Sheets-_Display_Files_of_the_Web06-00.png 354x334

Figure 3: The transformation from XSL into HTML gives this browser display.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: