The ABCs of XML - Part 3: XSLT

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.

Share Print Related RSS
Page 3 of 3 1 | 2 | 3 Next » View on one page

The source XML document separates parameter definition (<attribute>) from its value (<attribute_instance>). This template must normalize this information into a single parameter element so the resultant parameter table in Access will include its value as well as its data type, category, position on the control diagram, etc. The template is applied to each <attribute> so a variable is created that points to an <attribute_instance> of the same name within the same <module> from which the value is output.
A <ModuleTag> element must be added to each <Parameter> as a foreign key for relating a parameter to its parent <module> in the database.

The XML for the value of an <attribute_instance> differs for different data types. For example, an integer type value 25 is stored as <value><cv>25</cv></value>, whereas a named set type is stored as <value><string_value>some string</string_value></value>. The transform must return the value no matter what the data type.

 

Attribute Normal

<module tag=”FIC-101”
 plant_area=”TANKS”
 category=”FLOW”
 user=”johnsev”
 time=” 1095903496”>

Element Normal

<module>
  <tag>FIC-101</tag>
  <plant_area>TANKS</plant_area>
  <category>FLOW</category>
  <user>johnsev</user>
  <time>1095903496</time>
</module>

 

To support DeltaV named set data types, the output must include an <Enum> element that will contain the name of the named set found in the <attribute_instance>. This element must be included but empty for non-named set data types.

An attribute may be assigned multiple categories. A good relational design would have each category as a separate record in a related table. However, for simplicity sake, the category will be stored as a single field in the Parameter table as a comma-separated list.

The name and type attributes must be transformed to elements.

The parameter’s position on a control drawing defined by elements <x>, <y>, <h> and <w> must be transformed as children of the output <Parameter>.

Running the Sample
The sample files, including the results of the transformation, can be downloaded  at  www.controlglobal.com/XML3.html). Import the original XML file into MS Access both with and without the XSLT transformation to see the value of this transform and how well it performs.

Try this style sheet on your own DeltaV configuration—if you have one. If you have other XML data you would like to import into Access, try importing the data without a transform first. The XML structure may be suitable for import without a transform. If not, you have a great way to use what you’ve learned here and expand your reach with XSLT.

Conclusion
XSLT is a relatively easy language to master compared to a procedural language like VB. If you want to learn more you’ll find extensive online content and numerous publications. My personal favorite is XSLT Programmer’s Reference by Michael Kay from Wrox Press. The second edition covers XSLT 1.0 and 1.1. The third edition is also available which covers XSLT 2.0.

The final installment will provide more examples of using XSLT to transform XML data into something more useful.

XPath

Another standard from the W3C called XML Path Language (XPath) was developed for addressing parts of an XML document from within XSLT. XPath is a sort of query language for returning data subsets from an XML document that has its own syntax and rules like most languages. Within an XSLT stylesheet, an XPath expression may be used anywhere an XSLT element includes a select=”” attribute.

XPath expression look very similar to the pattern matching expressions in <xsl:template match=””> however the syntax and meaning of these expressions (match expression vs. select expression) is not the same. Most XSLT references provide a comparison of the differences between match expressions and select expressions otherwise known as XSLT Pattern Matching and XPath Expressions.

XSLT Processors

There are many XSLT processors available for download such as Saxon, Xalan and Microsoft MSXML. If you are working on a Windows XP computer, you already have a version of MSXML—most likely version 3 or version 4. All of the samples in this article were tested against MSXML4. The .NET framework also provides a .NET XSLT processor as well. Command line versions are available online for the XSLT processors mentioned here.

Different processors may produce slightly different results or may provide different extension functions that are not portable so to avoid problems it is a good idea to develop your transformations with a specific processor in mind.

 


  About the Author
John T. Sever, president of Cascade Controls, can be reached at johnsever@cascon.com.
Page 3 of 3 1 | 2 | 3 Next » View on one page
Share Print Reprints Permissions

What are your comments?

Join the discussion today. Login Here.

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments