以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 最新动态 & 业界新闻 』  (http://bbs.xml.org.cn/list.asp?boardid=35)
----  如何从 asp 传递参数给 xsl ??  (http://bbs.xml.org.cn/dispbbs.asp?boardid=35&rootid=&id=7006)


--  作者:haido
--  发布时间:4/25/2004 7:49:00 PM

--  如何从 asp 传递参数给 xsl ??
我现在有做一个小程序,其中有一个功能是这样的
我从select.asp 文件中根据<info>的不同选择显示cusbooks.xml中的信息

查询asp文件:select.asp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看信息</title>
</head>
<body>
<%
  sty=request.querystring("ty")
  dim osource
  dim ostyle
  set osource=server.createobject("microsoft.xmldom")
  osource.async=false
  set ostyle=server.createobject("microsoft.xmldom")
  ostyle.async=false
  select case sty
    case "1"
      osource.load server.mappath("cusbooks.xml")
      ostyle.load server.mappath("vbuy.xsl")
    case "2"
      osource.load server.mappath("cusbooks.xml")
      ostyle.load server.mappath("vbought.xsl")
  end select   
  response.write osource.TransformNode(ostyle)
%>  
</body>
</html>

xml 文件  cusbooks.xml
<?xml version="1.0" encoding="gb2312"?>
<cusbooks>
 <cusbook>
  <cusid>aaa</cusid>
  <booknum>c1</booknum>
  <info>bought</info>
  <order>order_1</order>
  <date>2004-4-22//17:51:00</date>
 </cusbook>
 <cusbook>
  <cusid>bbb</cusid>
  <booknum>c1</booknum>
  <info>buy</info>
  <order>none</order>
  <date>2004-4-25//16:04:17</date>
 </cusbook>
 <cusbook>
  <cusid>ccc</cusid>
  <booknum>f1</booknum>
  <info>buy</info>
  <order>order_2</order>
  <date>2004-4-25//16:15:48</date>
 </cusbook>
</cusbooks>

显示<info>为 bought 的xsl文件: vbought.xsl
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
  <html>
  <body>
    <table border="1" width="50%">
       <tr>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>订单号</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>成交日期</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>用户名</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>商品编号</b></font></th>
    </tr>
      <xsl:apply-templates select="cusbooks/cusbook" order-by="date"/>
    </table>
 </center>
  </body>
  </html>
</xsl:template>
<xsl:template match="cusbook[info='bought']">
              <tr>
                  <td><xsl:value-of select="order"/></td>
                  <td><xsl:value-of select="date"/></td>
                  <td><xsl:value-of select="cusid"/></td>
                  <td><xsl:value-of select="booknum"/></td>
              </tr>
</xsl:template>
</xsl:stylesheet>

显示<info>为 buy 的xsl文件: vbuy.xsl
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
  <html>
  <body>
     <table border="1" width="50%">
       <tr>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>订单号</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>成交日期</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>用户名</b></font></th>
    <th bgcolor="#ff0000"><font color="#ffffff" size="3"><b>商品编号</b></font></th>
    </tr>
      <xsl:apply-templates select="cusbooks/cusbook" order-by="date"/>
    </table>
 </center>
  </body>
  </html>
</xsl:template>
<xsl:template match="cusbook[info='buy']">
              <tr>
                  <td><xsl:value-of select="order"/></td>
                  <td><xsl:value-of select="date"/></td>
                  <td><xsl:value-of select="cusid"/></td>
                  <td><xsl:value-of select="booknum"/></td>
              </tr>
</xsl:template>
</xsl:stylesheet>

可以看到vbuy.xsl 和 vbought.xsl 仅仅区别在于[info='buy']和[info='bought"],请问高手,这个问题是不是能通过向xsl传递参数来解决? 非常谢谢。


--  作者:faly
--  发布时间:4/25/2004 10:13:00 PM

--  
参考一下[大富翁论坛]源码……
--  作者:haido
--  发布时间:4/27/2004 11:02:00 AM

--  
faly: 不好意思,[大富翁论坛]源码我看大不懂唉,能不能用最最简单的语言说明一下啊,多谢了。。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
7,171.875ms