xml| Tutorials | Getting Started | showing
By using XSL, you can add display information to an XML document.
Using XSL to display XML
XSL is the preferred XML Stylesheet language.
XSL is far more sophisticated than CSS. One way to use XSL is to convert it to HTML before the browser displays the XML file, as shown in the following examples:
To view an XML file:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
-<!--edited with XML Spy v2007 (http://www.altova.com)
-->
-<breakfast_menu>
-<food>
<name>belgian waffles</name>
<price>$5.95</price>
<description>two famous Belgian waffles with plenty to real maple syrup</description>
<calories>650</calories>
</food>
-<food>
<name>strawberry Belgian waffles</name>
<price>$7.95</price>
<description>light Belgian waffles covered with strawberries whipped and cream</description>
<calories>900</calories>
</food>
-<food>
<name>berry-berry Belgian waffles</name>
<price>$8.95</price>
<description>light Belgian Waffles covered with an assortment of fresh berries and whipped
<calories>900</calories>
</food>
-<food>
<name>french toast</name>
<price>$4.50</price>
<description>thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
-<food>
<name>homestyle breakfast</name>
<price>$6.95</price>
<description>two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
XSL style sheet:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
-<!--edited with XML Spy v2007 (http://www.altova.com)
-->
--<body style= "FONT-FAMILY:ARIAL,HELVETICA,SANS-SERIF;FONT-SIZE:12PT; Background-color: #EEEEEE ">
-<xsl:for-each select= "Breakfast_menu/food" >
-<div style= "background-color:teal;color:white;padding:4px" >
-<span style= "Font-weight:bold;color:white" >
<xsl:value-of select= "Name"/>
</span>
-
<xsl:value-of select= "Price"/>
</div>
-<div style= "margin-left:20px;margin-bottom:1em;font-size:10pt" >
<xsl:value-of select= "description"/>
-<span style= "Font-style:italic" >
(
<xsl:value-of select= "Calories"/>
Calories per serving)
</span>
</div>
</xsl:for-each>
</body>
View the results.
The following is a fragment of this XML file. The second line, <?xml-stylesheet type= "text/xsl" href= "simple.xsl", links this XML file to an XSL file:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<?xml-stylesheet type= "text/xsl" href= "simple.xsl"?>
<breakfast_menu>
<food>
<name>belgian waffles</name>
<price>$5.95</price>
<description>
Two of our famous Belgian waffles
</description>
<calories>650</calories>
</food>
</breakfast_menu>
If you need to learn more about XSL, please visit our XSL tutorial.