XSLT:<xsl:strip-space>不起作用 [英] XSLT: <xsl:strip-space> does not work

查看:26
本文介绍了XSLT:<xsl:strip-space>不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个 servlet 过滤器,它拦截所有传入的请求,并尝试从传入的 XML 中去除空格并将生成的干净"XML 写入响应.我正在使用 XSLT 来实现这一点.请参阅下面的 XSLT:

I have a servlet filter in my application that intercepts all the incoming requests and tries to strip the whitespaces from the incoming XML and write the resulting 'clean' XML to the response. I am using XSLT to achieve this. Please see the XSLT below:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@*|node()">
<xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

然而,这并没有按预期工作.生成的 XML 与原始 XML 相同(尽管在样式表中使用了 <xsl:strip-space elements="*"/>.

However, this is not working as expected. The resulting XML is the same as the original XML (despite of using the <xsl:strip-space elements="*"/> in the stylesheet.

请帮我解决这个问题.

问候,
- 艾许

Regards,
- Ashish

推荐答案

使用原始问题中的 xslt,一个 <xsl:template match="text()"><xsl:value-ofselect="normalize-space(.)"/></xsl:template> 应该可以解决问题.

Using the xslt from the original question, a <xsl:template match="text()"><xsl:value-of select="normalize-space(.)"/></xsl:template> should do the trick.

这篇关于XSLT:&lt;xsl:strip-space&gt;不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆