Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Incorporating Standards
Incorporating Standards

XML is just a tool, not a solution. Solutions come only when two or more entities agree to use the same format to share data.

The advent of XML has given birth to a number of groups that are developing these standards. But like any committee-based decision, it takes time to agree on what exactly those standards should be. You can't always wait for the standard to be completed. You need to exchange data with your clients/suppliers/partners today, but you don't want to do the work all over again when the standard becomes available. In some cases you've had a method for sharing data that's worked for quite a while and it's not feasible or reasonable to abandon that work. XSL Translation makes it possible to leverage your early work against any related XML document.

Let's assume you're already transferring data between your system and another using a format you designed (see Listing 1). As long as you get data in this format, your system is ready to import and process it. Along comes the long-awaited standard (see Listing 2) and, of course, even if your format is XML-based, it's entirely different and your partners are anxious to start using it. Or you're the one implementing the standard and your partners still need the data in the old format.

There's a way around rewriting your present methods of importing and/or exporting data. XSLT (eXtensible Stylesheet Language Translation) uses the power and even the format of XML to convert documents from any XML format to another structured format, XML or not. XSLT consists of an XML namespace that defines a set of elements, attributes, and other functions, including conditional and looping controls that make it a functional, if somewhat limited, language. XSLT engines process the XSLT document using an XML document as the input and deliver the data from the original document in the desired format. Most current XSLT is used to convert XML documents to HTML for Web site displays or to other XML documents; however, it's just as useful for generating delimited, fixed-length, or any structured format. Figure 1 shows how the XML and XSLT are processed to generate the target document.

Getting to the Data
The first task in creating a translation document is referencing specific elements and attributes of the source document. This is accomplished using yet another W3C Recommendation: XPath. XPath defines a syntax that returns elements, attributes, or text that meet specific location, value, or other criteria. A basic knowledge of XPath is required before creating any XSLT document, so here are the essentials.

If you're familiar with directory and file paths, XPath will be simple. Like most file systems, XPath references can be absolute (starting at the top of the document with a /) or relative (starting at the current point in the document). In addition, like most multiple file systems, a period or dot ( . ) refers to the current element and two periods or dots (..) refer to the parent of the current element.
In Listing 2:

/orders/order/customer/city
refers to the <city> element and if the <customer> element is current, then
./city
refers to the same <city> element and
../deliverymethod
refers to the <deliverymethod> element. Wild cards are also allowed, so that
/orders/order/customer/*
refers to the <name>, <address>, <city>, <state>, and <zip> elements. Collections or arrays can be referred to using an index. Whether the indexing is 0- or 1-based is dependant upon the XSLT engine, make sure you check with the vendor of the one you're using.

/orders/order/orderline[2]/price
refers to the <price> element in the second orderline with the $19.99 value. Attributes are referenced using an at sign (@).
/orders/order/orderline[1]/_ item@itemid
refers to the itemid attribute on the <item> element of the first <orderline> element with a value of "43-3398".

If your translation engine supports them, there are several functions that can be used in XPath to further refine the selection or output. For example:

/orders/order/orderline[last()]
refers to the last, in this case the second, order line.
starts-with(
orders/order/orderline/_
item@itemid,
'53'-)
refers to all items where the itemid begins 53-, in this case, the item in the second orderline.
substring-before(
orders/order/customer/name,
'')
refers to the text of the customer name before the first space, in this case, "Common."

Too Much, Too Little, Too Late
It's extremely unlikely that the order and content of the elements and attri- butes in the source document will match those of the target format. If your target format is XML, it's even more unlikely that the element names will match. If you're lucky enough that they do and your target format is XML, you'll make heavy use of xsl:copy, which duplicates an element, its attributes, and children. However, in most cases you'll use xsl:value-of to output the data (and use xsl:element and xsl:attribute if your target document is XML). You may also use xsl:text to generate nondata portions of the target document.

You can change the order within an instance of the data by simply placing the xsl:value elements in the order you want. Lines 66-70 in Listing 3 produce Mytown|KS|55593. For any element in the target document the source document will have the right amount of data, too much, or too little. XSLT provides constructs to handle nearly any conversion. The right amount of data is simple to convert. A simple xsl:value-of will handle it. Line 8 translates to Common Corporation.

Too much data can usually be handled by consolidating two or more elements from the source document using multiple xsl:value-of elements. This may require xsl:text to insert spaces or other separators. Lines 31-34 return [43-3398] 3/4 Inch Widget for the first orderline element in Listing 2.

Too little data has to be handled by using default values or determining the target values based on some portion or combination of the source document's values. This will probably create heavy use of the conditional and branching elements: xsl:if, xls:choose, xsl:when, and xsl:otherwise. The absence of a referenced element or attribute when using xsl:value-of doesn't cause an error. It may, however, cause other problems in the output. You can check for the existence of elements and attributes and handle them accordingly using xsl:if. Lines 38-43 place an N/A in the color spot when no color attribute is available. And Lines 14-25 determine the method of shipping (e.g., USMail or FedEx). Unlike a case statement in most languages, the test for each xsl:when in an xsl:choose can check completely different conditions on completely different items.

Since most data documents contain multiple instances of data or records, most translations require some kind of looping structure. XSL uses xsl:for-each to handle this. Looping can be further enhanced to include ordering using xsl:sort. This allows for further rearranging of the source document. Listing 3, lines 27-28, output the orderlines in order of the itemid.

If there are repetitive data structures (order, delivery, and billing addresses) in your documents, you'll be able to make use of the xsl:template functionality. It allows you to define the translation once and use it throughout the rest of your stylesheet by referencing it using xsl:apply-templates. Lines 54-72 show a template that formats the address of a customer into two address strings by concatenating everything past the first address element, separated by commas. It then adds a city, a state, and a zip code string.

Listing 3 is the complete XSLT document that converts the sample source document (see Listing 2) to the sample target document (see Listing 1). Since an XSL stylesheet is an XML document, run your XSLT documents through a parser to check that they're well formed and, if possible, for validity (a DTD fragment for XSLT is available from the W3C Web site). The details of applying a stylesheet to a specific XML document are particular to the translation engine you're using. Usually they consist of loading both the XSLT and the source documents and using a transform method that results in either a text string or a DOM object. As with any coding project, you'll need to test your stylesheet against all the possible data patterns to ensure that no errors are caused in processing or output.

New Version, Same Process
Once you have the XML standard document converted to your format, it can be processed as normal. Of course, then a new version of the standard will be released. It may be advantageous to continue to support the original standard until such time as the new version is prevalent. You can modify your XSLT stylesheet to fit the new standard or create an XSLT stylesheet to convert one standard document to the other. There are XSLT elements that are used to create well-formed XML output; most of them are self-explanatory. Listing 4 uses these functions to create the following:

<ordln> <itm itmid="43-3398" qty="1" prc="$3.59">3/4 Inch Widget</itm> </ordln>
These elements can obviously be used if your original data format is XMLbased as well.

Issues to Watch
As with other aspects of XML, whitespace is not handled consistently between, and sometimes within, translation engines. For the most part, if you don't want whitespace in your output, don't put it in your XSLT stylesheet.

The implementation record of HTML standards for browsers has been continued with translation engines as well. Some early versions implement few, if any, of the XPath functions and just the bare essentials of the XSLT elements and attributes. And the error messages generated when you use a feature not in your release are, as usual, less than explicit. Your best bet is to make sure you have the most up-to-date version and that the namespace you reference in your XSLT document corresponds to the requirements of the engine you're using. An incorrect namespace can cause incorrect output or, in some cases, no output at all.

When the W3C approves the schema specification later this year, standard formats for common data transfers should become more frequent. Using XSLT, you can leverage your existing integration solutions while working on your own XML-based methods. As those standards evolve, XSLT can help you manage the support of older versions using a single import method.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Swisscom, the Swiss telecom, is going into the cloud business. Its subsidiary Swisscom IT Services AG has signed up with Red Hat as a Certified Cloud Provider and launched a public cloud Infrastructure-as-a-Service (IaaS) cloud targeting enterprise-class customers primarily in ...
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP)....
In a surprise move on Tuesday, January 10, Oracle wheeled out its Big Data Appliance. That’s the one it said in October would be ready sometime in the first half. Only nobody believed it meant early in the first half. Heck, it’s not even clear anybody thought Oracle could make ...
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
CloudLinux, Inc., on Thursday released CafeFS 3, a virtualized file system for shared hosters that cages each customer within its own virtualized file system. CageFS becomes part of CloudLinux OS at no additional charge. CloudLinux OS, the only commercially-supported Linux OS m...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
As client demand for engagements increases, Revel Consulting (www.revelconsulting.com), a Kirkland, ...