Presents your
XML AND WEB SERVICES E-NEWSLETTER for November 10, 2003
<---------------Advertisement--------------->
REALIZE THE BENEFITS OF WEB SERVICES NOW!
Adopt Web services now and maximize the strategic and business
implications on ROI, vendor choice, and more. With TechRepublic's
Developer's Guide to Web Services, you'll have the tools, tips, and
resources to expand your knowledge of working with SOAP, Java/J2EE,
.NET, XML, WSDL, and more!
http://ct.com.com/click?q=f8-57bSQfsQKUlqTQ2Zb6lpiK_gel9T
<------------------------------------------->
XSL TRANSLATES WEB SERVICES APPLICATIONS
One common problem in Web services applications is that the back-end
software doesn't support XML (or at least not the XML that your Web
services
have standardized on). To defeat this problem, many architectures
employ
a translation stage that deciphers the incoming XML and converts it to
a
more appropriate format for the back-end systems. While there are many
ways you can translate your XML to a different format, eXtensible
Stylesheet Language (XSL) provides a robust, standard, and XML-friendly
solution.
SOME COMMON PROBLEMS
There are a variety of translations that might need to occur between
the
XML message and the application that will process it. However, there
are
also a handful of common problems, including:
* Lookup
* Mapping
* Aggregation
* Splitting
* Formulas
* Reordering
Lookup processes take an incoming value and map it to a different value
for the target system. For example, your XML has a value of 309, but
the
application needs a value of "Uber Widget."
Mapping essentially reassigns a value from one field to another. For
example, in the XML, you might have an AccountNumber element that needs
to
be assigned to a new element called CustomerAccountNumber.
Aggregation is the process of grouping two or more items from the XML
into a single item for the back-end system. A common example is the
combination of first and last name fields into a single name field.
Splitting is
the opposite of aggregation and involves decomposing an XML value into
two or more discrete components.
Formulas generally involve a computation on one or more XML values to
arrive at a new value for the application. One example is calculating
an
order total from subtotals in the XML.
Finally, reordering is the process of changing the sequence or
structure
of items in the XML so that they match the expected sequence or
structure of the target system.
A MAPPING EXAMPLE
Let's examine this process in more detail using a simple example. We'll
suppose that our incoming XML looks like LISTING 1.
Listing 1: webserviceorder.xml
8100
99213
-
2388
Uber Widget
15
10.95
-
6273
Flangeoid
10
52.00
Now, our order system needs a slightly different format. What we want
is
to convert the incoming order from the Web service to the format shown
in LISTING 2.
Listing 2: applicationorder.xml
99213
8100
2388
10.95
15
164.25
6273
52.00
10
520
THE TRANSLATIONS
Since this is a simplified example, there are only a few things we need
to do in our XSL template to translate our format. The first thing we
notice is that we have to map a few elements:
* Order to NewOrder
* AccountNumber to CustomerAccountNumber
* OrderNumber to CustomerOrderNumber
* Item to OrderItem
* PricePer to CustomerPrice
Next, we need to reorder the OrderItem elements under a new element
called OrderItems. Finally, we've added a new element called Subtotal
that
contains a calculation based on the price multiplied by the quantity.
The mapping translations are easiest because you simply define your new
element in the template and specify that it have the value of an
element
from the incoming XML document. The reordering of the Items is
accomplished by putting the Item subtemplate call within a new element
called
OrderItems. Finally, the calculation is handled using a simple XPath
expression.
LISTING 3 shows the XSL document used to convert from the incoming XML
to the application-specific XML.
Listing 3: translate.xsl
Brian Schaffner is an associate director for Fujitsu Consulting. He
provides architecture, design, and development support for Fujitsu's
Technology Consulting practice.
----------------------------------------