我正在尝试使用xslt删除XML中2个元素之间的空格。我最初使用content-as-a-string()函数将我的xml转换为字符串。这有助于我删除xml的缩进。但是,如下所示,每个元素之间存在单个空格。要求是删除之间的空格 的> <
<Employee> <EmployeeName>ABC</EmployeeName> <EmployeeID>123</EmployeeID> <EmployeeDate>11/13/2015</EmployeeDate> </Employee>
我需要的输出如下:
<Employee><EmployeeName>ABC</EmployeeName><EmployeeID>123</EmployeeID><EmployeeDate>11/13/2015</EmployeeDate></Employee>
获得正确的XSLT的任何帮助表示赞赏。另外,我只能使用xslt 1.0版本。 问候 Anooja
答案 0 :(得分:2)
简单的身份转换以及与文本节点匹配的模板并应用normalize-space()
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()"><xsl:value-of select="normalize-space(.)"/> </xsl:template>
</xsl:stylesheet>
请注意,这将规范化所有文本节点中的空格。
答案 1 :(得分:0)
在这种情况下我无法使用XSLT。因此使用java ReplaceAll函数并使用“// s +”替换所有空格,包括新行,空格等。
此致 Anooja