| Using XSLT to Describe HTML Output Using XML Input |
| Article Index |
|---|
| Using XSLT to Describe HTML Output Using XML Input |
| Page 2 |
XSLT is an XML document type definition adopted by the World Wide Web consortium (W3C) to carry data about how elements in an XML document should be mapped to visually defined HTML or XHTML elements suitable for display in a common Web browser.
Several modules in PHP provide the tools needed to help you to transform XML documents into their HTML or XHTML counterparts for display purposes, according to the XSLT templates that you provide.
XSL Stylesheets
XSL stylesheets are essentially XML-formatted lists of templates designed to match elements in an XML file whose document type is known in advance. Each time an element listed in the XSL stylesheet is found in the XML input document, the element and its associated data in the XML input document are replaced or altered according to the instructions given in the matching XSL stylesheet template.
For PHP users, the primary use of XSL stylesheets is for XSLT from XML- into HTML- or XHTML-formatted files. In short, XML elements in a document containing data that must be presented on the World Wide Web are transformed into HTML or XHTML tags according to the instructions given in the XSLT stylesheet file. Thus, the logical process of parsing an XML document into HTML or XHTML using XSLT goes something like this:
|
1. |
Parse an element in the XML-formatted input document.
|
|
2. |
Search for a template in the XSLT stylesheet that matches the newly parsed element. |
|
3. |
If a template is found that matches the element in question, replace the original element and data with new elements and (optionally) altered or transformed data, and process any additional XSLT instructions that occur in the matched template. |
|
4. |
If no template is found to match the element in question, do not process the element. |
|
5. |
Repeat this process for each element in the XML file until the entire element tree of the file in question has been processed. |
Given the number of tools available to PHP users through PHP extension modules such as DOM XML, XSLT, and XML, and given the flexibility of XSLT elements, the process can be made slightly more complex than thisbut this list of steps provides a simple and essential overview of the logic behind XSLT stylesheets and their interaction with XML files to produce HTML or XHTML documents.









