How to create an home page using xsl and jsp with header,footer and navbar written in separate file

Discussion in 'Java' started by Elena, May 3, 2007.

  1. Elena

    Elena Guest

    I'm doing a little web site with Netbeans using jsp and xsl. I've
    realized 3 xsl files (header,navbar,footer) containing a template with
    attribute name to visualize the 3 components, and index.xsl which
    should include the preceding files. Templates make an html
    transformation.
    I have also 4 jsp files (header.jsp,footer,navbar,index) containing
    data (taken from a database in MSAccess using javabeans) organized
    through xml tag. I'm trying to include header,navbar and footer (xsl)
    inside index.xsl,which displays the initial page seen by user, using
    <xsl:import> for the 3 components and <xsl:call-template name= > to
    apply the 3 template inside the template of index.xsl. I'm still green
    so I don't know if this solution is correct (at the moment it doesn't
    work:"impossible to compile the stylesheet"), or is there another
    better solution to realize header, navbar, footer in different files
    and make all work?
    I add some examples of files about which I'm working. they are very
    simple files just to see if my solution worked.

    FOOTER.JSP

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

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <c:set var="xmlDocument" scope="page">
    <PAGE></PAGE>
    </c:set>

    <c:set var="xslUrl"><%="/xsl/footer.xsl"%></c:set>
    <c:import var="xslDocument" url="${xslUrl}" scope="page"/>
    <x:transform xml="${xmlDocument}" xslt="${xslDocument}"/>


    FOOTER.XSL

    <?xml version="1.0" encoding="ISO8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.1">

    <xsl:template name= "foot">
    <xsl:eek:utput method="html" indent="yes"/>
    <html>
    <head>
    <title>Footer</title>
    </head>
    <body>
    <table width="100%" align="center" cellspacing="0"
    cellpadding="0">
    <tr><td align="center"><img src="/Bank/Images/
    hr.jpg" /></td></tr>
    </table>
    <table class="foot" align="center" cellspacing="0"
    cellpadding="0">
    <tr>
    <td><img src="/Bank/Images/Bank logo.jpg"
    height="40"/></td>
    <td><p> Bank Project</p></td>
    <td ><img src="/Bank/Images/Bank logo.jpg"
    height="40"/></td>
    </tr>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Xsl and jsp files for navbar and header are analogous, only names of
    template change.

    My solution for INDEX.XSL.

    <?xml version="1.0" encoding="ISO8859-1"?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.1">
    <xsl:import href="header.xsl"/>
    <xsl:import href="navbar.xsl"/>
    <xsl:import href="footer.xsl"/>

    <xsl:template match="/">
    <xsl:eek:utput method="html" indent="yes"/>
    <html>
    <xsl:call-template name="head"/>
    <xsl:call-template name="nb"/>

    <body>
    <table width="100%" height="100%" align="center"
    cellspacing="0" cellpadding="0">
    <tr>
    <td width="25%" align="center">Main page</
    td>
    <td width="50%" align="center">Main page</
    td>
    <td width="25%" align="center">Main page</
    td>
    </tr>
    </table>
    <body>

    <xsl:call-template name="foot"/>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    INDEX.JSP

    <%@ page info="Pagina iniziale" %>
    <%@ page contentType="text/html" %>
    <%@ page session="false" %>
    <%@ page buffer="30kb" %>
    <%@ page errorPage="/ErrorPage.jsp" %>

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

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <c:set var="xmlDocument" scope="page">
    <PAGE></PAGE>
    </c:set>
    <c:set var="xslUrl"><%="/xsl/index.xsl"%></c:set>
    <c:import var="xslDocument" url="${xslUrl}" scope="page"/>

    <x:transform xml="${xmlDocument}" xslt="${xslDocument}"/>
    Elena, May 3, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EvgueniB
    Replies:
    1
    Views:
    623
    Anthony Borla
    Dec 15, 2003
  2. Frank Fredstone
    Replies:
    1
    Views:
    436
    Jean-Francois Briere
    Jun 27, 2006
  3. Matthias
    Replies:
    0
    Views:
    539
    Matthias
    Aug 8, 2006
  4. Elena
    Replies:
    0
    Views:
    864
    Elena
    May 3, 2007
  5. Henrik
    Replies:
    1
    Views:
    423
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page