以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  请大家帮我看一下这个用 xsl 显示 xml 的问题?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=20722)


--  作者:evilwolf125
--  发布时间:7/27/2005 2:05:00 PM

--  请大家帮我看一下这个用 xsl 显示 xml 的问题?
请大家帮我看一下这个用 xsl 显示 xml 的问题?

xml文档:
<?xml version="1.0" encoding = "gb2312"?>

<!DOCTYPE booklist[
<!ELEMENT booklist (book)+>
<!ELEMENT book (title,author,price,publish,content)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (firstname,lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT publish (#PCDATA)>
<!ELEMENT content (#PCDATA)>
]>

<?xml-stylesheet type="text/xsl" href = "test_1_1.xsl"?>

<booklist>
<book>
  <title> "vc++ 技术内幕 " </title>
  <author>
   <firstname> 潘</firstname>
   <lastname> 爱民</lastname>
  </author>
  <price> 62.00 </price>
  <publish>清华大学出版社</publish>
  <content> <![CDATA["我们都是中国人<你好>;"]]> </content>
</book>
<book>
  <title> 深入浅出mfc </title>
  <author>
   <firstname> 候</firstname>
   <lastname> 捷 </lastname>
  </author>
  <price> 88.00</price>
   <publish>adsfasdf</publish>
  <content> mfc 的深入剖析</content>
</book>  
</booklist>

xsl文档:
<?xml version="1.0"?>
<xsl:stylesheet  xmlns:xsl = "http://www.w3.org/TR/WD-xsl"
  
   >
<xsl:template>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match = "/">
<html>
<head>
<title> booklist </title>
</head>
<body>
  
         <xsl:apply-templates select = "booklist"/>
</body>
</html>
</xsl:template>
<xsl:template match = "booklist">
  
  <table border = "0">
     <xsl:for-each select = "book">
   <tr>
    <th> 书名:</th>
    <td> <xsl:value-of select = "title"/></td><br>
   </tr>
   <tr>
    <th> 作者:</th><br>
    <td> <xsl:value-of select = "author/firstname"/> <xsl:value-of select = "author/lastname"/> </td><br>
   </tr>
   <tr>
    <th> 价格:</th><br>
    <td> <xsl:value-of select = "price"/></td><br>
   </tr>
   <tr>
    <th> 出版社:</th><br>
    <td> <xsl:value-of select = "publish"/></td><br>
   </tr>
   <tr>
    <th> 内容:</th><br>
    <td> <xsl:value-of select = "content"/></td><br>
   </tr>
   </xsl:for-each>
  </table>
  

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

感觉没有错,为什么不能显示呢?
老是提示 <th>错误的信息



--  作者:菜籽
--  发布时间:7/27/2005 10:57:00 PM

--  
修改xsl如下,可以显示

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
  <html>
    <head>
      <title> booklist </title>
    </head>
    <body>
      <xsl:apply-templates select="booklist"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="booklist">
  <table border="0">
     <xsl:for-each select="book">
       <tr>
          <th>书名:</th>
          <td><xsl:value-of select="title"/></td><br/>
       </tr>
       <tr>
          <th>作者:</th><br/>
          <td><xsl:value-of select="author/firstname"/><xsl:value-of select="author/lastname"/></td><br/>
       </tr>
       <tr>
          <th>价格:</th><br/>
          <td><xsl:value-of select="price"/></td><br/>
       </tr>
       <tr>
          <th> 出版社:</th><br/>
          <td> <xsl:value-of select="publish"/></td><br/>
       </tr>
       <tr>
          <th>内容:</th><br/>
          <td><xsl:value-of select="content"/></td><br/>
       </tr>
   </xsl:for-each>
  </table>
</xsl:template>

</xsl:stylesheet>


--  作者:evilwolf125
--  发布时间:8/9/2005 11:05:00 AM

--  
老兄我按照你说的做了,还是不能正确显示,提示是th错误,怎么回事啊
--  作者:Dannys_Lee
--  发布时间:8/11/2005 12:13:00 AM

--  
将xsl文档里 "<br>" 该为"<br/>"即可,本人已经试过了,OK.

<?xml version="1.0"?>
<xsl:stylesheet  xmlns:xsl = "http://www.w3.org/TR/WD-xsl">
<xsl:template>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match = "/">
<html>
<head>
<title> booklist </title>
</head>
<body>
  
         <xsl:apply-templates select = "booklist"/>
</body>
</html>
</xsl:template>
<xsl:template match = "booklist">
  
  <table border = "0">
     <xsl:for-each select = "book">
   <tr>
    <th> 书名:</th>
    <td> <xsl:value-of select = "title"/></td><br/>
   </tr>
   <tr>
    <th> 作者:</th><br/>
    <td> <xsl:value-of select = "author/firstname"/> <xsl:value-of select = "author/lastname"/> </td><br/>
   </tr>
   <tr>
    <th> 价格:</th><br/>
    <td> <xsl:value-of select = "price"/></td><br/>
   </tr>
   <tr>
    <th> 出版社:</th><br/>
    <td> <xsl:value-of select = "publish"/></td><br/>
   </tr>
   <tr>
    <th> 内容:</th><br/>
    <td> <xsl:value-of select = "content"/></td><br/>
   </tr>
   </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>


--  作者:菜籽
--  发布时间:8/11/2005 12:16:00 PM

--  
楼主的浏览器升级一下啊。是不是版本太低了
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
125.000ms