Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

From the author of

Transforming Documents

Although XML is an excellent format for storing information, in many cases it's necessary to reformulate the information into another format for consumption by a particular application. The process of taking an XML document and reformulating it is called transformation.

The Extensible Stylesheet Language (XSL) is the de facto standard for transforming and displaying XML documents. The two branches of XSL cover transforming XML into another format (XSLT) and describing page layouts using a specialized XML vocabulary (XSL-FO). The most common way to present XML data to users today is to transform it (using XSLT) into HTML, which can be displayed directly by any web browser. However, in the future, generating printed documentation (using XSL-FO and a tool such as FOP) will be at least as important as web presentation.

For the Web

Transforming XML for use by a web browser is one of the most common tasks facing an application developer today. A few web browsers (such as IE version 5.0 and above) can perform an XSLT transformation on the client. But because most web sites don't want to limit their audiences, web site developers tend to perform transformations directly on the server and send HTML content to the browser.

For Printing

Although online viewing of XML data is a very common task, being able to generate both online and offline (printed) versions of a document is a very powerful concept. Keeping online and offline content synchronized is a difficult task for most companies, and integrating the two with XML can provide numerous benefits.

For Different Applications

As companies begin to share more and more information with their suppliers, customers, and partners, the need to transform from one XML format to another will increase. Take, for example, the following XML document that represents a simple parts order for Company A:

<?xml version="1.0" encoding="UTF-8"?>
<order>
 <item quantity="1" SKU="235144"/>
 <item quantity="2" SKU="519151"/>
</order>

As long as both parties in the transaction use the same precise XML format for orders, this can be sent directly from Company A to Company B for fulfillment. But suppose that Company B's order format looks like this:

<?xml version="1.0" encoding="utf-8"?>
<order>
 <SKU count="1">235144</SKU>
 <SKU count="2">519151</SKU>
</order>

The order from Company A would not be recognized by Company B's system. Because XSLT can be used to generate XML as well as HTML output, the first order can be transformed automatically into the second order using a simple XSLT script:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="order">
  <order>
   <xsl:for-each select="item">
    <SKU count="{@quantity}"><xsl:value-of select="@SKU"/></SKU>
   </xsl:for-each>
  </order>
 </xsl:template>
</xsl:stylesheet>

When companies can tightly couple their key information systems, they become more competitive than before. XSL transformations can be used to facilitate this type of integration.

  • + Share This
  • 🔖 Save To Your Account