Understanding
the basics of XML and XSLT is very easy if you get a good tutorial where
you can work on it and learn it side by side. You have to work on it
to understand how it works. Consider the following XML file,
_______________________________________________
<?xml
version="1.0" encoding="ISO-8859-1"?>
<books>
<book>
<title>The Other side of Midnight</title>
<author>Sidney Sheldon</author>
</book>
.
.
.
</books>
The above
file has data related to the stocks of the books available. The title
and the author of the book is store in the elements <book> of
the XML file. The elements <title> and <author> hold the
text data of the title and the author.
Now we
have to create an XSL file that will format the data available in the
XML file. It is better to use tools like XMLSpy to create an XSL file
since you can learn it easily and see the transformation done on the
same window. The XSL file created is 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 in Stock</h2>
<table border="1">
<tr bgcolor="#eeeeee">
<th align="left">Title</th>
<th align="left">Author</th>
</tr>
<xsl:for-each select="books/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
Go through
the XSL file and you would find that the XSL tags are used in between
the html tags and you can understand how the data is formatted.
A 'xsl:for-each'
loop is used to loop through all the <book> tags and retrieve
the values of <title> and <author>. For this purpose the
'xsl:value-of' tag is used. Lots of similar examples are available in
the internet. You can use a good tutorial to understand the concepts
and the tags used in XSL.