以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  xslt表格镶嵌问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=74596)


--  作者:Natsumi
--  发布时间:4/30/2009 7:45:00 PM

--  xslt表格镶嵌问题
xml格式
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="req3.xsl"?>
<cars>
 <car transmission="manual" engine="petrol">
  <make>Nissan</make>
  <model>Primera</model>
  <cc>1500</cc>
  <year>1996</year>
  <price>7999.99</price>
  <colour>Green</colour>
  <image-filename>primera.jpg</image-filename>
  <email>bob@carsales.com</email>
  <feature>air conditioning</feature>
  <feature>CD player</feature>
 </car>
 <car transmission="automatic" engine="petrol">
  <make>Holden</make>
  <model>Vectra</model>
  <cc>2200</cc>
  <year>2001</year>
  <price>10999.95</price>
  <colour>Red</colour>
  <image-filename>vectra.jpg</image-filename>
  <email>mary@carsales.com</email>
  <feature>Mags</feature>
  <feature>Turbo</feature>
  <feature>Stripes</feature>
 </car>
 <car transmission="manual" engine="diesel">
  <make>Toyota</make>
  <model>Corolla</model>
  <cc>1800</cc>
  <year>1998</year>
  <price>8000</price>
  <colour>Blue</colour>
  <image-filename>corolla.jpg</image-filename>
  <email>pete@carsales.com</email>
 </car>
</cars>


xsl格式
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
   doctype-public="-//W3C//DTD XHTML 1.1//EN"
   doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
    <title>Cars</title>
   </head>
   <body>
    <h1>Cars</h1>
    <xsl:apply-templates select="cars/car"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="car">
  <p><xsl:attribute name="class">
   <xsl:value-of select="cars/car[@transmission and @engine]"/>
   </xsl:attribute>
  Car: <xsl:value-of select="make"/>
  <xsl:choose>
     <xsl:when test="@transmission='manual' and @engine='petrol' ">
     <img>
     <xsl:attribute name="src">
     <xsl:value-of select="/car/image-filename"/>
     </xsl:attribute>
     <xsl:attribute name="alt">primera</xsl:attribute>
     </img>
     </xsl:when>
     <xsl:when test="@transmission='automatic' and @engine='petrol' ">
     <img><xsl:attribute name="src">
     <xsl:value-of select="/car/image-filename"/>
     </xsl:attribute>
     <xsl:attribute name="alt">vectra</xsl:attribute>
     </img>
     </xsl:when>
     <xsl:when test="@transmission='manual' and @engine='diesel' ">
     <img><xsl:attribute name="src">
     <xsl:value-of select="/car/image-filename"/>
     </xsl:attribute>
     <xsl:attribute name="alt">corolla</xsl:attribute>
     </img>
     </xsl:when>
   </xsl:choose>
    </p>
  <table>
    <tbody>
     <tr>
     <th>model</th>
     <th>cc</th>
     <th>year</th>
     <th>price</th>
     <th>colour</th>
     <th>email</th>
     <th>feature</th>
    </tr>
    <xsl:for-each select="cars/car">
     <tr>
      <td>
       <xsl:value-of select="model"/>
      </td>
      <td>
       <xsl:value-of select="cc"/>
      </td>
      <td>
       <xsl:value-of select="year"/>
      </td>
      <td>
       <xsl:value-of select="price"/>
      </td>
      <td>
       <xsl:value-of select="colour"/>
      </td>
      <td>
       <xsl:value-of select="email"/>
      </td>
      <td>
       <xsl:value-of select="feature"/>
      </td>
      </tr>
 </xsl:for-each>
 </tbody>
  </table>
</xsl:template>
</xsl:stylesheet>

我是菜鸟啊啊啊啊
怎么弄出的表格只有标题没有内容啊。。求助高手啊。。。


--  作者:Qr
--  发布时间:4/30/2009 8:19:00 PM

--  
既然<xsl:template match="car">
为什么匹配其下子节点还用<xsl:value-of select="/car。。"/>
路径全错了
应该直接匹配子节点,

还有<xsl:value-of select="cars/car[@transmission and @engine]"/>是什么意思?


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms