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>