是在客户端IE上做转化还是在服务端做转化?
如果在服务端,用个DOM对象处理方便些,
但按你的意思应该是在客户端了。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"/>但是我试了下,好像也没办法把xml再转换为xml,在ie上总是按html来解释还有一个方法
java org.apache.xalan.xslt.Process -IN a.xml -XSL a.xsl -OUT b.xml
自己去找那个相应的包。还有看看下面这段代码能不能对你有些提示
<?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>
如果在服务端,用个DOM对象处理方便些,
但按你的意思应该是在客户端了。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"/>但是我试了下,好像也没办法把xml再转换为xml,在ie上总是按html来解释还有一个方法
java org.apache.xalan.xslt.Process -IN a.xml -XSL a.xsl -OUT b.xml
自己去找那个相应的包。还有看看下面这段代码能不能对你有些提示
<?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>
解决方案 »
- jsp中连接数据库时出错
- Hibernate中 外键参照的只能是另一表的主键吗?
- 大量使用session导致jvm内存占用太高,想优化却不知从何下手
- 有Hibernate关继承映射的问题[在CSDN和GOOGLE搜到的贴都没这问题,搞了两天都找不到错在哪~请达人们指教下]
- 急!struts中 大小写问题???
- (高分)求jsprun论坛的开发文档
- 请问tomcat支持分布式事务处理功能吗
- struts动态表单的问题????一直不解
- jboss中如何配置sqlserver数据源(详细说明)
- Java 怎么实现根据消息ID和状态 ,调用类不同方法
- 在ibatis里使用proxool连接池有可能吗?
- 讨论一种框架的可行性
xsl:output method = "xml"
这个方法是为了区分一些 html和xml的语法差别 例如<br>和<br/>
不如直接使用字符串替换把XML文件读到字符串里面,然后replaceAll("<(/?)a(/?)>","<$1aaaaa$2>")
-----------------------
还有看看下面这段代码能不能对你有些提示
<?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>
-------------------------就是类似这样的东东,使用递归来处理
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "xml" indent = "yes"/>
<xsl:template match="/|@*"
<xsl:copy>
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="@*>
</xsl:copy>
</xsl:template> <xsl:template match="node()">
<xsl:if test="name(.)='a'">
<aaaaa>
<xsl:copy-of select="@*"/>
</aaaaa>
</xsl:if>
<xsl:if test="not(name(.)='a')">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy
</xsl:if>
</xsl:template
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "xml" indent = "yes"/>
<xsl:template match="/|@*"
<xsl:copy>
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="@*>
</xsl:copy>
</xsl:template> <xsl:template match="node()">
<xsl:if test="name(.)='a'">
<aaaaa>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</aaaaa>
</xsl:if>
<xsl:if test="not(name(.)='a')">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy
</xsl:if>
</xsl:template
</xsl:stylesheet>
<?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" indent = "yes"/>
<xsl:template match="/|@*">
<xsl:copy>
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template> <xsl:template match="node()">
<xsl:if test="name(.)='a'">
<aaaaa>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</aaaaa>
</xsl:if>
<xsl:if test="not(name(.)='a')">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
转换后得到的文件
<?xml version="1.0" encoding="UTF-8"?>
<root>
<nls>
<aaaaa>测试</aaaaa>
</nls>
<aaaaa>
<b>测试b</b>
</aaaaa>
<aaaaa>测试c</aaaaa>
</root>