zoukankan      html  css  js  c++  java
  • 使用XSLT将XML转换为XHTML

    1.示例

    cdcatalog.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
    <catalog>
        <cd>
            <title>Empire Burlesque</title>
            <artist>Bob Dylan</artist>
            <country>USA</country>
            <company>Columbia</company>
            <price>10.90</price>
            <year>1985</year>
        </cd>
    .
    .
    </catalog>
    

    cdcatalog.xsl

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html> 
    <body>
      <h2>My CD Collection</h2>
      <table border="1">
        <tr bgcolor="#9acd32">
          <th style="text-align:left">Title</th>
          <th style="text-align:left">Artist</th>
        </tr>
        <xsl:for-each select="catalog/cd">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
        </xsl:for-each>
      </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    

    2.遇到的问题


    用浏览器直接打开cdcatalog.xml,显示一片空白。
    去掉这一行<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>就好了。

    显然这不是我们想要的效果,我们希望XSLT能将XML转换为HTML。

    3.解决问题

    于是,尝试把cdcatalog.xmlcdcatalog.xsl都放到服务器上就好了!

    参考:

  • 相关阅读:
    AS中Loading 的加载
    视频类的相关加载
    2012、10、05 听课笔记
    2012、09、27 听课笔记
    小程序的编写—2
    小程序的编写—1
    2012、9、28 听课笔记
    GCD
    CFHTTP
    获取当前时间字符串
  • 原文地址:https://www.cnblogs.com/gzhjj/p/13533917.html
Copyright © 2011-2022 走看看