求助!!!

xslinger 2006-04-16 12:10:29
请教各位大哥:
  我想根据jsp面产生的不同的xml,用xsl关联用IE打开显示,但是浏览器总是只显示出一个条件下产生出的xml ,另一个条件下显示输出的xml总是不对,总是前一个xml显示形式。我想问一下是不是我的xsl文件哪有问题

我的jsp文件如下:
<%@ page contentType="text/xml; charset=GB2312" pageEncoding="gb2312"%>
<%@ include file="common.jsp" %>
<%@ page import="java.util.*" %>

<%
//Get the identifier of the book to display
String bookId = request.getParameter("bookId");
if(bookId.equals(""))bookId="201";
BookDetails book = bookDB.getBookDetails(bookId);


%>
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="bookdetails.xsl" ?>
<top>
<% if(book==null){

%>
<bookdetails>

<bookid> <% out.println(bookId); %></bookid>
<have>no</have>
<path><% out.println(request.getContextPath()); %></path>
</bookdetails>
<%}
else{
%>
<bookdetails>
<bookid>
<% out.println(book.getBookId()); %>
</bookid>
<have>yes</have>
<path>
<% out.println(request.getContextPath()); %>
</path>
<booktitle>
<% out.println(book.getTitle()) ; %>
</booktitle>
<bookname>
<% out.println(book.getName()) ;%>
</bookname>
<bookyear>
<% out.println(book.getYear());%>
</bookyear>
<bookprice>
<% out.println(book.getPrice()); %>
</bookprice>
<booksalecount>
<% out.println(book.getSaleAmount()); %>
</booksalecount>
<description>
<% out.println(book.getDescription()); %>
</description>

</bookdetails>
<%}%>
</top>


我的bookdetails.xsl如下:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" >
<xsl:template match="/">
<html>
<head><title>TitleBookDescription</title></head>
<body>
<xsl:if test="./top/bookdetails/have[text()='no']">
<xsl:apply-templates select="./top/bookdetails" mode="no"/>
</xsl:if>
<xsl:if test="./top/bookdetails/have[text()='yes']">
<xsl:apply-templates select="./top/bookdetails" mode="yes"/>
</xsl:if>
</body>
</html>
</xsl:template>

<xsl:template match="bookdetails" mode="no" >
<p>号为<xsl:value-of select="./bookid"/>的书不存在</p>
<strong><xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="./path"/>/catalog.jsp
</xsl:attribute>
继续购物
</xsl:element>
</strong>
</xsl:template>


<xsl:template match="bookdetails" mode="yes">
<p>书名:<xsl:value-of select="./booktitle"/></p>
作者: <em><xsl:value-of select="./bookname"/> </em>
(<xsl:value-of select="./bookyear" /> )<br></br>
<p>价格(元):<xsl:value-of select="./bookprice"/></p>
<p>销售数量:<xsl:value-of select="./booksalecount"/></p>
<p>评论:<xsl:value-of select="./description"/></p>
<p><strong><xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="path"/>/catalog.jsp?Add=<xsl:value-of select="bookid"/>
</xsl:attribute>继续购物
</xsl:element></strong></p>
</xsl:template>

</xsl:stylesheet>


...全文
136 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

8,907

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧