Presents your XML E-NEWSLETTER for September 27, 2002 ---------------------------------------- ACCESSING MULTIPLE DOCUMENTS WITH XSLT This special TechMail delivers the skills and know-how so you can manage the needs and support the demands of the XML working environment. Below is a sample of what you'll find on the DEVELOPER'S GUIDE TO XML CD-ROM. http://cl.com.com/Click?q=12-jaAKIl-bil48-KR-pj-zYpqxqGZR Extensible Stylesheet Language Transformations (XSLT) provides a robust set of functions for transforming one XML document into another. This is particularly useful when incoming or outgoing XML documents don't match the document type expected by the target system. There are many times when the target system might expect a single document even though the source data is being distributed across multiple documents. We can solve this problem by using XSLT to transform multiple-source documents into a single XML document. A SAMPLE PROBLEM We'll start by defining a simple scenario to illustrate the problem. Assume our customers are going to send us their orders using XML documents. We want to protect the price information in the XML documents because different customers have different negotiated prices, which can change often. Rather than put a per-item price in the XML, the customers will enter the price code for the particular item. For simplicity, we'll say that there are five price codes being used based on the letters A through E. Each price code corresponds to the dollar amount listed in our proprietary Price.xml document, which we update regularly. Unfortunately, our target order system doesn't understand Price.xml. Instead, it expects each line item in the order to have a real price value when input into the system. THE ORDER As the orders come in, we want to translate the element into a element. We'll do this using XSLT's document() function and an XPath expression to extract the correct price code. ---------------------------------------- If you find this XML information helpful, you'll want our DEVELOPER'S GUIDE TO XML. Get in-depth articles on XML basics, programming, databases, Web services, and security; plus you'll get sample XML coding to get you started. http://cl.com.com/Click?q=27-z9ZmIqItaRlIIurSkCFPV2l-83sR ---------------------------------------- THE DOCUMENT() FUNCTION AND XPATH Using the document() function, you can access multiple XML documents from within your XSLT template. You can open as many documents as you need. The basic process we'll use to open and access external documents is to assign the node of the Price.xml document to a variable inside the translation and then use XPath to query that node for the particular price. To open a document and assign it to a variable, use the following syntax in your XSLT template: This will open the Price.xml document in the current directory, find the node, and assign it to the prices variable. Now we can query this node to extract a price for a particular code using XPath. To translate the price code into the price, you would use something like the following: This extracts the value of the PriceCode from the input document into a variable called $letter. Then, it uses the $letter variable to identify a particular price using an XPath query. Below is a snippet of our XSLT template that will put all of this together. AN EASY WAY TO GATHER YOUR INFO Using XSLT templates to translate XML documents can be a very powerful way to move data from one system to another. Sometimes, this can be challenging if the source data is in multiple documents. You can use XSLT's document() function to access the data in multiple XML documents to solve this problem. Learn More about ordering your copy of DEVELOPER'S GUIDE TO XML! http://cl.com.com/Click?q=40-6Pp4IdnRD7vBealeVUTmn-qzKCrR ----------------------------------------