Share this Page URL

Chapter 16. Working with XML Data in Acc... > Presenting XML Data with Access - Pg. 580

Working with XML Data in Access 580 and apply transforms to that document. This work typically happens in memory before the document is rendered for the user to see. The following code sample illustrates how VBScript loads the .xsl file into the DOM for processing. (I added line numbers for ease of exposition. If you open the file in Notepad, you won't see line numbers.) 1. Dim objData, objStyle 2. Set objData = CreateDOM 3. LoadDOM objData, "CampaignExpenses.xml" 4. Set objStyle = CreateDOM 5. LoadDOM objStyle, "CampaignExpenses.xsl" 6. Document.Open "text/html","replace" 7. Document.Write objData.TransformNode(objStyle) Lines 1, 2, and 4 create space in the computer's memory for the containers that will hold the files. Line 3 loads the XML document into memory, and line 5 loads the XSL into memory. Line 6 tells the computer to open a new HTML document and replace the existing HTML document in the browser with the new one. Line 7 then applies the transform by reading the code in the XSL, applying it to the XML, and creating that new HTML document in memory. So how does the XSL create this new HTML document? Open the XSL in Notepad, and we'll take a brief look at how it works. As with the .xsd file, the .xsl file is fairly complex, and we'll cover only the basics here. In general, the XSL is a small program that parses the XML, finds elements within the XML, writes out lines of HTML that contain formatting tags applied to data elements, and creates any other presentational elements needed. In our example, it creates a table and puts the data elements in the appropriate rows and columns. Part of the XSL is HTML that will be copied as-is into the new HTML document. The other part is program code (VBScript again) that will dynamically build certain elements and apply specific formatting to elements. Let's look at a section of code that creates the table structure and places one of the field names in the first cell: