From XML Data to HTML Tables, Page 2
The XSLT File
This file is named XSL003.xsl. It shows how to use XSLT to transform the contents of a simple XML database into an HTML table.
I will also discuss this XSLT file in fragments. A complete listing of the file is presented near the end of the lesson.
The following code shows the preliminary material at the beginning of the file. I discussed this material in detail in a previous lesson, and won't repeat that discussion here.
Create an HTML table
You will recall, any literal text that is not inside a processing element is simply passed through and inserted into the output. This code shows some of the literal text necessary to create an HTML table. If you don't know the purpose of these attributes of an HTML table element, I'm sure that you can find that information at dozens of places on the web.
At the beginning of each iteration, the code creates a new row in the table using an HTML <tr> element. For each row, it uses three successive xsl:value-of processing elements to extract the contents of the three elements named title, author, and price.Insert each content value into a table cell
The contents of each XML element are inserted into a cell in the HTML row by wrapping them in an HTML table data element indicated by <td>. Then the entire populated row of HTML text is inserted into the output text stream.Cleanup time again
Finally, here are the ending tags for the HTML elements that are being created as well as the ending tags for the XSLT template and stylesheet elements:
Now let's look at some output.