Login | Register
Print page
Email page

Home » The ABCs of XML - Part 3: XSLT

The ABCs of XML - Part 3: XSLT

ControlGlobal.com

Keywords: XML, XSLT, programming, language, industrial automation and software

This article provides more of what you need to know to survive in the world of connected data by introducing the XSLT programming language, which brings the benefits of XML to industrial automation applications.

The ABCs of XMLBy John T. Sever, President, Cascade Controls

XML data is increasingly prevalent in the world of industrial automation. System vendors provide options for data interchange through XML, and industry organizations adopt XML as a standard for data transport, such as the OPC Foundation’s OPC XML-DA specification. Still, many front-line automation engineers find no benefit to old data restructured in XML alone. The benefits they seek may be found in technologies designed to support, consume and manipulate XML data. One such technology from the World Wide Web Consortium is a language specifically designed for transforming or restructuring an XML document into something else. The eXtensible Stylesheet Language Transformations (XSLT) is a simple, yet powerful language that can bring enormous benefit to those willing to learn it.

RELATED ARTICLES

The ABCs of XML: Part I
The ABCs of XML, Part 2


 

In this article, I will introduce the basics of XSLT through an example derived from an actual customer request. My coverage of the topic will be limited by the space available in this format however, I hope to awaken interest in a technology that might otherwise be overlooked and thereby give to some, a hint of the benefits waiting to be uncovered.

The Project
My customer maintains a large DeltaV automation system in an FDA-qualified environment. The customer would like a tool that simplifies daily demands of managing a large configuration. Such a tool, we have determined, is most easily developed around a relational database. Therefore we must transfer the configuration from control system to database in a structure that best supports the requirements of this tool.

A prototype of this tool is under development using Microsoft Access 2003 because of its built-in features for reporting and rapid application development. One such feature is the ability to import XML data through the File menu (File/Get External Data/Import), allowing the application of an XSLT transform before importing. This feature imports element-normal XML data by creating new tables with structures based upon those found in the XML document. The user optionally may choose to append data to existing tables following a set of mapping rules that match table and field names to element names in the XML document.

     FIGURE 1: THE XSLT TRANFORMATION PROCESS
XSLT Transformation Process

Restructure XML data or transform XML into an alternate text format.

The Transformation
Unfortunately, the XML structure of a DeltaV configuration does not match the desired data structures to meet our analysis requirements, so the raw XML data must be restructured or transformed into a different XML structure better suited to the customer’s requirements. Before learning the benefits of XSLT, I would have solved this problem by writing VBA code to load the XML document and programmatically walk the tree of nodes, adding new records to database tables using either the DAO or ADO object models. The XSLT solution presented here requires less code, is more robust, easier to develop, easier to maintain and modify, and is significantly faster than the VBA solution.

    

SAMPLE FILES
(Including results of the transformation)

The XSLT style sheet restructures the XML for importing control modules and their parameters (See Sample Files). By dissecting this style sheet, I will explain basic XSLT concepts, while explaining solutions to common data structure problems.

ADVERTISEMENT

Before reading on, get familiar with the basic structure of a DeltaV XML file. Notice that each control module is defined in a <module> element that has attributes for tag, plant_area, category, user and time. Also review the <attribute> and <attribute_instance> elements that are children of a <module> element.


More content on this topic:

Free Subscriptions

Control Digital Edition

Access the entire print issue on-line and be notified each month via e-mail when your new issue is ready for you. Subscribe today.