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

    >> XML与各种文件格式的相互转换及相关工具。 word to xml, xml to word, html to xml, xml to pdf,
    csv to xml, rtf to xml, text to xml, xml to text, xls to xml, xml to xls
    FOP
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 WORD to XML, HTML to XML 』 → How to convert XML files to the HTML.[推荐] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 27401 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: How to convert XML files to the HTML.[推荐] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     阳光不老 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(C++考了100分!)
      文章:37
      积分:384
      门派:XML.ORG.CN
      注册:2004/10/18

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给阳光不老发送一个短消息 把阳光不老加入好友 查看阳光不老的个人资料 搜索阳光不老在『 WORD to XML, HTML to XML 』的所有贴子 访问阳光不老的主页 引用回复这个贴子 回复这个贴子 查看阳光不老的博客楼主
    发贴心情 How to convert XML files to the HTML.[推荐]

    Introduction
    You have an XML document ,you need to convert into a more readable file format. For example, you have personnel data that is stored as an XML document and you need to display it on a web page or in a text file.

    Solution
    The solution for this is to use an XSLT stylesheet to transform the XML into another format using the XslTransform class. In the example code, we are transforming some personnel data from a fictitious business stored in Personnel.xml. First, we load the stylesheet for generating HTML output, then we perform the transformation to HTML via XSLT using the PersonnelHTML.xsl stylesheet. After that, we transform the data to comma-delimited format using the PersonnelCSV.xsl stylesheet:

    Expand code snippet
    public static void TransformXML( )

    {

          // Create a resolver with default credentials.

          XmlUrlResolver resolver = new XmlUrlResolver( );

          resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

          // transform the personnel.xml file to html

          XslTransform transform = new XslTransform( );

          // load up the stylesheet

          transform.Load(@"..\PersonnelHTML.xsl",resolver);

          // perform the transformation

          transform.Transform(@"..\Personnel.xml",@"..\Personnel.html",resolver);

          // transform the personnel.xml file to comma delimited format

          // load up the stylesheet

          transform.Load(@"..\PersonnelCSV.xsl",resolver);

          // perform the transformation

          transform.Transform(@"..\Personnel.xml", @"..\Personnel.csv",resolver);

    }

    The Personnel.xml file contains the following items:

    <?xml version="1.0" encoding="utf-8"?>

    <Personnel>

         <Employee name="Shahab" title="Customer Service" companyYears="1"/>

         <Employee name="Noosha" title="Manager" companyYears="12"/>

         <Employee name="NavidChas" title="Salesman" companyYears="3"/>

         <Employee name="Mehrdad" title="CEO" companyYears="27"/>

    <Personnel>

    The PersonnelHTML.xsl stylesheet looks like this:

    Collapse
    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

               xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:template match="/">
    <html>
    <head />

      <body title="Personnel">

         <xsl:for-each select="Personnel">

         <p>

         <xsl:for-each select="Employee">

         <xsl:if test="position( )=1">

              <table border="1">

              <thead>

              <tr>

                        <td>Employee Name</td>

                        <td>Employee Title</td>

                        <td>Years with Company</td>

              </tr>

           </thead>

           <tbody>

           <xsl:for-each select="../Employee">

               <tr>

               <td>

                  <xsl:for-each select="@name">

                  <xsl:value-of select="." />

                  </xsl:for-each>

             </td>

             <td>

                  <xsl:for-each select="@title">

                  <xsl:value-of select="." />

                  </xsl:for-each>

            </td>

            <td>

                  <xsl:for-each select="@companyYears">

                  <xsl:value-of select="." />

                  </xsl:for-each>

            </td>

            </tr>

            </xsl:for-each>

          </tbody>

          </table>

          </xsl:if>

    </xsl:for-each>

    </p>

    </xsl:for-each>

    </body>

    </html>

    </xsl:template>

    </xsl:stylesheet>

    Here is the HTML source:

    Collapse
    <html xmlns:xs="http://www.w3.org/2002/XMLSchema">

    <head>

    <META http-equiv="Content-Type" content="text/html; charset=utf-8">

    </head>

    <body title="Personnel">

         <p>

         <table border="1">
         <thead>

         <tr>

              <td>Employee Name</td>

              <td>Employee Title</td>
              <td>Years with Company</td>

         </tr>
         </thead>
      
         <tbody>

         <tr>
              <td>Shahab</td>

              <td>Customer Service</td>
              <td>1</td>

         </tr>

         <tr>
              <td>Noosha</td>

              <td>Manager</td>
              <td>12</td>

         </tr>

         <tr>
              <td>Navid</td>

              <td>Salesman</td>
              <td>3</td>

         </tr>

        <tr>
             <td>Mehrdad</td>

             <td>CEO</td>
             <td>27</td>

        </tr>

        </tbody>
        </table>

        </p>

    </body>

    </html>

    The comma-delimited output is generated using PersonnelCSV.xsl and Personnel.xml; the stylesheet is shown here:

    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:

    xs="http://www.w3.org/2002/XMLSchema">

    <xsl:output method="text" encoding="UTF-8"/>

    <xsl:template match="/">

    <xsl:for-each select="Personnel">

    <xsl:for-each select="Employee">

    <xsl:for-each select="@name">

    <xsl:value-of select="." />

    </xsl:for-each>,<xsl:for-each select="@title">

    <xsl:value-of select="." />

    </xsl:for-each>,<xsl:for-each select="@companyYears">

    <xsl:value-of select="." />

    </xsl:for-each>

    <xsl:text> </xsl:text>

    </xsl:for-each>

    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

    The output from the PersonnelCSV.xsl stylesheet is shown here:

    Shahab,Customer Service,1
    Noosha,Manager,12
    Navid,Salesman,3
    Mehrdad,CEO,27


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    规矩网络 Refree.Cn 打造中国顶级的资源重组网站!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/10/27 13:31:00
     
     tomcat7911 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:8
      积分:98
      门派:XML.ORG.CN
      注册:2006/10/10

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给tomcat7911发送一个短消息 把tomcat7911加入好友 查看tomcat7911的个人资料 搜索tomcat7911在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看tomcat7911的博客2
    发贴心情 
    还是英文的
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/11/22 15:18:00
     
     东方伯 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:13
      积分:106
      门派:XML.ORG.CN
      注册:2007/8/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给东方伯发送一个短消息 把东方伯加入好友 查看东方伯的个人资料 搜索东方伯在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看东方伯的博客3
    发贴心情 
    还需要学习啊,好多看不懂!

    ----------------------------------------------
    一张盗版的windows光盘上写着:“正版费用我们在清王朝时已经付过了,所以无须激活,尽请放心使用!”

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/8/2 21:17:00
     
     fangel2000 帅哥哟,离线,有人找我吗?
      
      
      头衔:w3china第一水王
      等级:大四寒假(收到Microsoft的Offer啦)
      文章:283
      积分:1503
      门派:W3CHINA.ORG
      注册:2006/5/30

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给fangel2000发送一个短消息 把fangel2000加入好友 查看fangel2000的个人资料 搜索fangel2000在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看fangel2000的博客4
    发贴心情 
    有没有好点的 “convert HTML to XML” 的啊,大家给推荐一下啊
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/10/27 17:07:00
     
     bigon2000 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:10
      积分:99
      门派:XML.ORG.CN
      注册:2008/5/7

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给bigon2000发送一个短消息 把bigon2000加入好友 查看bigon2000的个人资料 搜索bigon2000在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看bigon2000的博客5
    发贴心情 
    路还很长啊...而且还很苦...努力学习....
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/6/11 16:40:00
     
     andy天使鱼 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:2
      积分:58
      门派:XML.ORG.CN
      注册:2008/12/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给andy天使鱼发送一个短消息 把andy天使鱼加入好友 查看andy天使鱼的个人资料 搜索andy天使鱼在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看andy天使鱼的博客6
    发贴心情 
    没看懂啊
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/12/5 12:28:00
     
     hjx_221 帅哥哟,离线,有人找我吗?
      
      
      威望:7
      等级:博士一年级
      文章:4607
      积分:24021
      门派:XML.ORG.CN
      注册:2004/8/30

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hjx_221发送一个短消息 把hjx_221加入好友 查看hjx_221的个人资料 搜索hjx_221在『 WORD to XML, HTML to XML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hjx_221的博客7
    发贴心情 
    祝福牛年万事平安顺利,新春愉快

    ----------------------------------------------
    初从文,三年不中;后习武,校场发一矢,中鼓吏,逐之出;遂学医,有所成。自撰一良方,服之,卒~ 
    http://hjx221.blogger.org.cn/

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

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

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