|MICRO CENTER: COMPUTERS AND ELECTRONICS|
| Tech Take-Apart
Introduction to XML, Part III
To begin, I went back to my kparticles_final.xsl file where I previously wrote a basic template for my XML using tables. There are a couple of ways in which you can add styles to your XML through XSLT. The first option is to add inline styles with CSS or use XSL-FO notation. In this example, I am just plugging in my CSS tags that I declared in my external CSS file.
I continued integrating my inline CSS tags for each of the table cells, and then tested my results in a browser. The final results look like this:
As mentioned before, there is another way of formatting your XML using XSL-FO language. This is a specialized notation that integrates with the XSLT template to control layout and presentation. To use XSL-FO, you need to declare the namespace at the top of your XSLT document as follows:
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">The word "root" represents the root element name for your XML file. Each tag has to have the fo: prefix to apply the formatting. Here is an example of what the table in my XSLT file might look like using XSL-FO:
<?xml version="1.0" encoding="ISO-8859-1"?>XSL-FO is also very useful when styling XML for print layout. You can control the flow of your pages by restricting data to be placed in a specific region or to flow onto the next page. For a more detailed tutorial on XSL-FO, visit W3schools.com.
Once your XML formatting is finished, you need an XSLT engine to render your template. There are several software tools available for free or paid. Some XSLT engines available are Saxon-B, Xalan, or Altova. These require some additional set up to run. Try XML Problem-Design-Solution tutorials for a step by step on installing Saxon-B and Xalan.
With your XSL template set up, you still are left with the task of keeping your XML data current. There is a more efficient way of managing your information using Excel. In the example below, I've imported my original XML file into Excel by going to Data -> XML -> Import. Excel places all of the data in order based on the XML tree hierarchy. From here, it is much easier to edit your data and export it for updates rather than making changes in a text editor.
Another way to use of XML is exporting data from a SQL database. Depending on the volume of information, it would take next to forever to format a web site with hundreds of items by using plain HTML. By incorporating XSLT, this is done automatically with your prepared template. Though utilizing XML for your data takes some planning, the long term benefits of saving time and managing your content efficiently makes it worthwhile.
© Micro Center