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:


 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="">

<xsl:template match="/">
    <table border="0">
      <tr bgcolor="#fff">
<!--for every row node -->
      <xsl:for-each select="rows/row">
<!--select name node-->
        <td><xsl:value-of select="name"/></td>
<!--select surname node-->
        <td><xsl:value-of select="surname"/></td>
<xsl:template match="//rows" mode="appointments">


Finally we have to create the jsp page

<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="x" uri="" %>

  <title>Java-Only Example</title>
<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}"/>