|
XML: The Data, XSL: The Presentation |
|
|
Although XSL is a powerful language that can be used to create different sorts of output documents, our interest is with its HTML generation capability. Having an XML and an XSL document as input, an XSLT processor can produce an HTML document. To make this happen, no matter which enabling technology is used, the application programs should provide data in XML format. Without thinking in which page, in what order, with which font-size and background color will it be displayed the application programmers concentrate purely on providing data. After making a connection to a database and executing a SQL query through it, a Java programmer can create an XML as follows:
The XML string created will be something similar to the following.
The data is ready in XML format. Now what remains is the XSL. It would not be wrong if you think of XSL as a language that is embedded in an HTML document and pulls the required data from an XML document. The XSL below repeats the second row of the table for each item element in the XML and pulls the values of Name, Stock and Price elements that exist under the item element and inserts between the <td> and </td> tags of the row.
You may ask where the difference is? In the previous example we inserted VB codes in the HTML now we're inserting codes in another language. If you did not recognize the difference, I tell you. Do you see any database connection or any business logic inserted into the HTML? No, because XSL is just a style sheet language. It does not create data; but it can perfectly transform or format the provided data. Beyond that, XSL is a W3C recommendation that means it is a world standard not a vendor specific language. Please recall that the HTML page in the previous section had lost its feature of being standard after inserting the VB codes in it whereas the HTML in this example is still standard with embedded XSL instructions in it and can be used with any type of server side technology.
|