是在客户端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>
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>