zoukankan      html  css  js  c++  java
  • 利用xslt对xml进行缩进格式化处理

     下面就是简单的例子,这里提供2中方法:
      test.htm 
     
      
      
    <SCRIPT> 
      
    //装载数据 
      x = "<r><a name='net_lover'>aaaaaaaaaaa</a> <b>bbbbbbb</b><a>aaaaaaaaaaa</a><b>bbbbbbb</b></r>" 
      
    var source = new ActiveXObject("Msxml2.DOMDocument"); 
      source.async 
    = false
      source.loadXML(x) 
      alert(source.xml) 
       
      
    // 装载样式单 
      var stylesheet = new ActiveXObject("Msxml2.DOMDocument"); 
      stylesheet.async 
    = false
      stylesheet.resolveExternals 
    = false
      stylesheet.load(
    "style.xsl"); 
      alert(stylesheet.xml) 
       
      
    // 创建结果对象 
      var result = new ActiveXObject("Msxml2.DOMDocument"); 
      result.async 
    = false
       
      
    // 把解析结果放到结果对象中方法1 
      source.transformNodeToObject(stylesheet, result); 
      alert(result.xml) 
       
      
    // 把解析结果放到结果对象中方法2 
      result2 = "" 
      result2 
    = source.transformNode(stylesheet); 
      source.loadXML(result2) 
      alert(source.xml) 
      
    </SCRIPT> 
       

       
      style.xsl 
     
      
      
    <?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()"> 
      
    <xsl:copy> 
      
    <xsl:apply-templates select="@* | node()"/> 
      
    </xsl:copy> 
      
    </xsl:template> 
      
    </xsl:stylesheet> 
       
  • 相关阅读:
    idea打开项目,没有项目文件,文件报红
    使用lombok自动生成链式调用
    gson常用的方式
    LOADING Redis is loading the dataset in memory Redis javaAPI实例
    redis.clients.jedis.exceptions.JedisDataException :READONLY You can't write
    Redis安装步骤
    springboot+jpa+mysql+redis+swagger整合步骤
    springboot+jpa+mysql+swagger2.0整合
    Daily Scrum 10.23
    Daily Scrum 10.22
  • 原文地址:https://www.cnblogs.com/ryb/p/460091.html
Copyright © 2011-2022 走看看