Adr*_*ian 3 xml xslt removing-whitespace
我写了一个小XSLT,我在其中添加normalize-space()了删除不必要空格的函数:
http://xsltransform.net/bnnZWM
<xsl:template match="page/pageFunctionResult/*/text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
XSLT本身可以工作,除了一些空格没有规范化:
<category> TEST </category>
Run Code Online (Sandbox Code Playgroud)
我不明白为什么normalize-space()不能删除这些空格.
正如评论中所指出的,角色真的是非空洞的角色(#160).要将它们作为常规空间处理,请使用:
<xsl:value-of select="normalize-space(translate(., ' ', ' '))"/>
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)[3] S ::= (#x20 | #x9 | #xD | #xA)+
周围的人物TEXT在你的链接的例子是不是这些字符(如@ har07在评论中指出)。根据@michael.hor257k 对 的巧妙使用string-to-codepoints(),
<xsl:template match="page/pageFunctionResult[1]/category[1]">
<xsl:value-of select="string-to-codepoints(substring(., 1, 1))"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我们可以看到它们是NO-BREAK SPACE字符 (#xA0),又名 .
要删除 ,您需要的不仅仅是normalize-space()....
如果你想覆盖 与其他类型的空白字符,以及使用replace()带有类别逃生提前normalize-space():
<xsl:value-of select="normalize-space(replace(., '\p{Z}', ' '))"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1880 次 |
| 最近记录: |