WebReference.com - Part 2 of chapter 12 of XSLT Developer's Guide, from Osborne/McGraw-Hill (2/4) | WebReference

WebReference.com - Part 2 of chapter 12 of XSLT Developer's Guide, from Osborne/McGraw-Hill (2/4)

To page 1current pageTo page 3To page 4
[previous] [next]

XSLT Developer's Guide

A Sample B2B Problem

Let us consider an example that highlights the important aspects of B2B application integration. Consider a retailer that receives products from a large number of suppliers. Currently, the retailer manages the inventory of these goods using an ERP system and places orders for products using the phone, fax machines, and so forth. The suppliers, in turn, receive the orders and enter the data manually in their back-end systems. The retailer wants to streamline the B2B interactions with its suppliers and gain efficiencies by eliminating paperwork to the extent possible. This is expected to improve the response time of the suppliers and help the retailer manage a just-in-time inventory. For this to happen, the retailer wants to build a web-based B2B application that will enable its purchasers to enter orders using a browser. These orders will be electronically placed, and the suppliers will receive the relevant data almost instantly. The suppliers, in turn, prevent costly errors in data entry through the automation of that process and can store the order data in their back-end systems. For a given supplier, orders can then be viewed by the employees of the shipping department using a web browser, who can respond to the orders and accept or reject them. If they accept an order, they enter information such as the delivery date, terms of the invoice, and so forth and submit the response. From that point on, the order is processed following the existing business processes. The supplier's response goes back to the retailer electronically, and the relevant data is then entered into the retailer's back-end systems.

The key steps in the new B2B interaction are listed here:

The key hurdle in this scenario is that the supplier and the retailer use their own data formats to store the same information, which may very well be incompatible. Hence, a data transformation must occur at the retailer's end (or the supplier's end) to ensure that the transformed data follows the specifications of the supplier. This scenario presents an excellent opportunity for the use of XML and XSLT. The supplier as well as the retailer can use a mechanism to extract data from (or insert data into) their respective back-end systems as XML trees. Each of them can (and generally will) follow their own internal specifications to determine the structure of the XML trees. XSLT can then be used to transform one source tree into another.

For example, let us say that the retailer wants to send the order in the form of the following source tree, RetailerOrder.xml:

<?xml version="1.0"?>
  <Order OrderID=1001>
  <Product ProductID="2001">
    <Name>Widget1</Name>
    <Department>Ceramic processing</Department>
    <Buyer>
      <First_name>Jean-luc</First_name>
      <Last_name>Picard<Last_name>
    </Buyer>
    <NegotiatedPrice Currency="US Dollar">2005</NegotiatedPrice>
    <Quantity>5000</Quantity>
    <Description>
      Our retail company describes the product in its own terms.
    </Description>
    <Comments>A very important widget in our production process. Orders
      will get installed without this product. Therefore, at least a
      one-month supply of this product should be held in reserve.
    </Comments>
  </Company>
</Order>

Let us say that the supplier in question uses an XML tree (here, a result tree), SupplierOrder.xml, that looks like this:

<?xml version="1.0" encoding="utf-8"?>
  <Order>
    <Company>The Big Retailer</Company>
    <OrderID>1001</OrderID>
    <Product ProductID="2001">
      <Name>Widget1</Name>
      <Description>
          Our retail company describes the product in its own terms.
      </Description>
    </Product>
    <Department>Ceramic processing</Department>
    <BuyerName>Picard,Jean-luc</BuyerName>
    <NegotiatedPrice Currency="US Dollar">2005</NegotiatedPrice>
    <Quantity>5000</Quantity>
    <DateNeeded>22-DEC-2002</DateNeeded>
</Order>

Thus, our task is to write a stylesheet that will support the B2B integration between the retailer and the supplier by transforming the source tree RetailerOrder.xml into the result tree SupplierOrder.xml. Notice that the result tree differs from the source tree in the following respects:

The stylesheet Retailer2Supplier.xsl required for this B2B integration is shown here:

<?xml version="1.0"?>
<!-- stylesheet specifications begin -->
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="Company">
    <Order>
    <Company>
      <xsl:value-of select="@CompanyName"/>
    </Company>
     <xsl:apply-templates/>
    </Order>
  </xsl:template>
  <xsl:template match="Order">
      <OrderID>
      <xsl:value-of select="@OrderID"/>
      </OrderID>
      <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="Product">
    <!-- Output the Product node exactly as it is in the source tree -->
    <xsl:text disable-output-escaping="yes">
      <Product ProductID="
    </xsl:text>
    <xsl:value-of select="@ProductID"/>
    <xsl:text disable-output-escaping="yes">"></xsl:text>
    <Name>
      <xsl:value-of select="./Name"/>
    </Name>
    <Description>
      <xsl:value-of select="./Description"/>
    </Description>
    <xsl:text disable-output-escaping="yes"></Product></xsl:text>
  </xsl:template>
  <xsl:template match="Department">
    <Department>
      <xsl:value-of select="."/>
    </Department>
  </xsl:template>
  <xsl:template match="Buyer">
    <BuyerName>
      <xsl:value-of select="./Last_name"/>,
      <xsl:value-of select="./First_name"/>
    </BuyerName>
</xsl:template> <xsl:template match="NegotiatedPrice"> <!-- Output the Product node exactly as it is in the source tree --> <xsl:text disable-output-escaping="yes"> <NegotiatedPrice Currency=" </xsl:text> <xsl:value-of select="@Currency"/> <xsl:text disable-output-escaping="yes">"></xsl:text> <xsl:value-of select="."/> <xsl:text disable-output-escaping="yes"> </NegotiatedPrice> </xsl:text> </xsl:template> <xsl:template match="Quantity"> <Quantity> <xsl:value-of select="."/> </Quantity> </xsl:template> <xsl:template match="DateNeeded"> <DateNeeded> <xsl:value-of select="."/> </DateNeeded> </xsl:template> </xsl:stylesheet>

More often than not, the form of the result tree will differ from one supplier to the next—hence the need to write multiple stylesheets. Of course, the result trees will share some commonalities, and therefore you will be able to find efficiencies by having the common transformations in one stylesheet and importing that into another that contains the rest of the transformations required to support the business needs of that supplier.


To page 1current pageTo page 3To page 4
[previous] [next]

Created: June 3, 2002
Revised: June 3, 2002


URL: http://webreference.com/authoring/languages/xml/xsltdev/chap12/2/2.html