新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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转化xml格式问题, 急!!![求助] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4657 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 使用XSLT转化xml格式问题, 急!!![求助] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     xiaoyupan 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:10
      积分:135
      门派:XML.ORG.CN
      注册:2006/7/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xiaoyupan发送一个短消息 把xiaoyupan加入好友 查看xiaoyupan的个人资料 搜索xiaoyupan在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xiaoyupan的博客楼主
    发贴心情 使用XSLT转化xml格式问题, 急!!![求助]

    使用XSLT转化xml格式问题, 急!!!
    源xml格式
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <Book name="XML">
     <Chapter no="1">
      <Section no="1">
      </Section>
      <Section no="2">
      </Section>
      <Section no="3">
      </Section>
     </Chapter>
     <Chapter no="2">
      <Section no="1">
      </Section>
      <Section no="2">
      </Section>
      <Section no="3">
      </Section>
     </Chapter>
     <Chapter no="3">
     </Chapter>
    </Book>

    目标格式
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <Book name="XML">
     <Chapter no="1">
      <Section no="1"/>
      <Section no="2"/>
      <Section no="3"/>
     </Chapter>
     <Chapter no="2">
      <Section no="1"/>
      <Section no="2"/>
      <Section no="3"/>
     </Chapter>
     <Chapter no="3"/>
    </Book>

    也就是说, 将<Section no="1">   
      </Section> 等元素
    和  <Chapter no="3">
      </Chapter>
    转换成<Section no="1"/> 和 <Chapter no="3"/>

    由于xml文件很大, 所以想给转换一下便于阅读. 我用下面的XSLT转换没有效果, 请高人指点谜津!
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method = "xml"  omit-xml-declaration = "yes" indent = "yes"/>
      <xsl:strip-space elements="*"/>
      <xsl:template match="/ | @* | node()" priority="0.5">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    手册上说, 用 strip-space 可以去掉空白, 但是对此毫无效果.


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/10/27 6:36:00
     
     W3 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:10
      积分:111
      门派:XML.ORG.CN
      注册:2006/10/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给W3发送一个短消息 把W3加入好友 查看W3的个人资料 搜索W3在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看W3的博客2
    发贴心情 
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <xsl:element name="BOOK">
          <xsl:attribute name="name">XML</xsl:attribute>
          <xsl:for-each select="//Chapter">
            <xsl:element name="Chapter">
              <xsl:attribute name="no">
                <xsl:value-of select="@no"/>
              </xsl:attribute>
              <xsl:for-each select="Section">
                <xsl:element name="Section">
                  <xsl:attribute name="no">
                    <xsl:value-of select="@no"/>
                  </xsl:attribute>
                </xsl:element>
              </xsl:for-each>
            </xsl:element>
          </xsl:for-each>
        </xsl:element>
      </xsl:template>
    </xsl:stylesheet>
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/10/30 9:19:00
     
     xiaoyupan 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:10
      积分:135
      门派:XML.ORG.CN
      注册:2006/7/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xiaoyupan发送一个短消息 把xiaoyupan加入好友 查看xiaoyupan的个人资料 搜索xiaoyupan在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xiaoyupan的博客3
    发贴心情 
    感激不尽! 马上就试一试!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/10/30 21:52:00
     
     xiaoyupan 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:10
      积分:135
      门派:XML.ORG.CN
      注册:2006/7/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xiaoyupan发送一个短消息 把xiaoyupan加入好友 查看xiaoyupan的个人资料 搜索xiaoyupan在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xiaoyupan的博客4
    发贴心情 
    发现了个简单的方法!! 由于文件大而复杂, 下面的方法较为合适和通用, 贴出与大家共享:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method = "xml"  omit-xml-declaration = "yes" indent = "yes"/>
      <xsl:template match="/ | @* | node()" priority="0.5">
        <xsl:copy>
          <xsl:choose>
            <xsl:when test="count(node())>0">
              <xsl:apply-templates select="@* | node()"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="@*"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>

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

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

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