Remove newline character/white space from xml using xslt or xquery transformation

六月ゝ 毕业季﹏ 提交于 2019-12-25 06:33:48

问题


How to remove newline character/white space from xml using xslt or xquery transformation.Means all the elements will come in a single line.


回答1:


In xslt, you can add a top level element

<xsl:strip-space elements="*"/>

By using a sample input XML below:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <a>XXX</a>
    <b>YYY</b>
    <c>ZZZ</c>
</root>

and the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>

    <!-- this is called an identity template -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

produces:

<?xml version="1.0" encoding="utf-8"?><root><a>XXX</a><b>YYY</b><c>ZZZ</c></root>


来源:https://stackoverflow.com/questions/22803218/remove-newline-character-white-space-from-xml-using-xslt-or-xquery-transformatio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!