There are definitely many ways to parse an xml document and display the data in a jsp.In this tutorial we will se how to transform an xml document to html format using an XSLT document and JSTL XML tags.

As an example,lets say that the xml document  looks like this:

<rows>
	<row>
		<name>theName</name>
		<surname>theSurname</surname>
	</row>
	<row>
		<name>theName</name>
		<surname>theSurname</surname>
	</row>
	<row>
		<name>theOtherName</name>
		<surname>theOtherSurname</surname>
	</row>
	<row>
		<name>theThirdName</name>
		<surname>theThirdSurname</surname>
	</row>
	<row>
		<name>theFourthName</name>
		<surname>theForthSurname</surname>
	</row>
</rows>

 In order to display the data of the above xml document as html we will use an xslt document that look like this:

<?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="/">
  
    <table border="0">
      <tr bgcolor="#fff">
        <th>Name</th>
        <th>Surname</th>
      </tr>
<!--for every row node -->
      <xsl:for-each select="rows/row">
      <tr>
<!--select name node-->
        <td><xsl:value-of select="name"/></td>
<!--select surname node-->
        <td><xsl:value-of select="surname"/></td>
      </tr>
      </xsl:for-each>
    </table>
</xsl:template>
<xsl:template match="//rows" mode="appointments">

</xsl:template>
</xsl:stylesheet>

Finally we have to create the jsp page

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<head>
  <title>Java-Only Example</title>
</head>
<body>
<h3>Rows info:</h3>

<c:import url="/xslt/transform.xsl" var="xsltdoc"/>
<c:import url="/xml/document.xml" var="xmldoc"/>

<x:transform xml="${xmldoc}" xslt="${xsltdoc}"/>

</body>
</html>