使用 xslt 或 xquery 转换从 xml 中删除换行符/空格 [英] Remove newline character/white space from xml using xslt or xquery transformation
本文介绍了使用 xslt 或 xquery 转换从 xml 中删除换行符/空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 xslt 或 xquery 转换从 xml 中删除换行符/空格.意味着所有元素都将出现在一行中.
How to remove newline character/white space from xml using xslt or xquery transformation.Means all the elements will come in a single line.
推荐答案
在xslt中,可以添加顶级元素
In xslt, you can add a top level element
<xsl:strip-space elements="*"/>
通过使用下面的示例输入 XML:
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>
以及以下 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>
产生:
<?xml version="1.0" encoding="utf-8"?><root><a>XXX</a><b>YYY</b><c>ZZZ</c></root>
这篇关于使用 xslt 或 xquery 转换从 xml 中删除换行符/空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文