XML Getting Started Tutorial: Using XSL to display XML

Source: Internet
Author: User
Tags version xml stylesheet xmlns xsl xsl file
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.