本文介绍了XSLT:如何忽略不必要的空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于此示例 XML 文件:

Given this example XML file:

<doc>
<tag>

    Hello !

</tag>
<tag>
    My
    name
    is
    John
</tag>
</doc>

以及以下 XSLT 表:

And the following XSLT sheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:for-each select="doc/tag">
        <xsl:value-of select="."/>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

我应该如何更改它以忽略换行并将任何一组空白字符转换为项目中的一个空格?换句话说,我想获得:

How should I change it in order to ignore line feeds and convert any group of white-space characters to just one space in the items? In other words, I would like to obtain:

Hello!
My name is John

没有那些愚蠢的换行符....问题是如何.

Without all those those silly line feeds. ...the question is how.

提前致谢!

推荐答案

<xsl:template match="tag">
  ...
  <xsl:value-of select="normalize-space(.)" />
  ...
</xsl:template>

其实有一个.

这篇关于XSLT:如何忽略不必要的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 10:27
查看更多