Learn XML stylesheet with example

There are lots of examples in the internet that help you to learn xml and stylesheet. You can make changes to the source xml file and see how it is changed in the result. Consider for example that you have an xml file like,


_______________________________________________

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="books_style.xsl"?>
<books>
<book>
<author>Author Name 1</author>
<title>Book Title 1</title>
</book>
.
.
.
</books>

If you look at the xml file given above you can see that it contains a list of books details with author of the book and the title of the book. There are many <book> nodes in it that has <author> and <title> child nodes. The second line of that xml file indicates the stylesheet which is used to format the data in the xml file. The style sheet "books_style.xsl" is included using the <?xml-stylesheet….?> tag.

The code in the "books_style.xsl" file could be something like,

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Books List</h2>
<table border="1">
<tr bgcolor="#eeeeee">
<th align="left">Author</th>
<th align="left">Book Title</th>
</tr>
<xsl:for-each select="books/book">
<tr>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

After you create this .xsl file and that .xml file, you can try to view that xml file in the browser. Now you will not see the tree like structure as you would normally see the xml files. Check it out!




_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________







 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.