新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → xslt表格镶嵌问题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 9122 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: xslt表格镶嵌问题 举报  打印  推荐  IE收藏夹 
       本主题类别: 样式表技术(XSL, XSLT, XSL-FO, CSS) | DOM    
     Natsumi 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:1
      积分:53
      门派:XML.ORG.CN
      注册:2009/4/30

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Natsumi发送一个短消息 把Natsumi加入好友 查看Natsumi的个人资料 搜索Natsumi在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看Natsumi的博客楼主
    发贴心情 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>

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


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/4/30 19:45:00
     
     Qr 帅哥哟,离线,有人找我吗?
      
      
      威望:9
      等级:博士二年级(版主)
      文章:4392
      积分:29981
      门派:XML.ORG.CN
      注册:2004/5/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Qr发送一个短消息 把Qr加入好友 查看Qr的个人资料 搜索Qr在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Qr的主页 引用回复这个贴子 回复这个贴子 查看Qr的博客2
    发贴心情 
    既然<xsl:template match="car">
    为什么匹配其下子节点还用<xsl:value-of select="/car。。"/>
    路径全错了
    应该直接匹配子节点,

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

    ----------------------------------------------
    没人帮忙,那就靠自己,自己才是最好的老师!本人拒绝回答通过站内短消息提出的问题!

    blog:http://Qr.blogger.org.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/4/30 20:19:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/28 0:04:48

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    61.981ms