xsl:strip-space不会删除回车符

use*_*147 5 xml xslt

这是xml文件."CategoryName"元素中的空格和回车符是有意的.

<?xml version="1.0" encoding="utf-8"?>
<group>
    <item>
        <id>item 1</id>
        <CategoryName>


        </CategoryName>
    </item>
    <item>
        <id>item 2</id>
        <CategoryName></CategoryName>
    </item>
    <item>
        <id>item 3</id>
        <CategoryName>      </CategoryName>
    </item>

</group>
Run Code Online (Sandbox Code Playgroud)

以下是上述XML文件的XSLT文件.它应该做的是它将清除"CategoryName"元素中的所有空格.然后,它将测试"CategoryName"是否为空.

<?xml version="1.0" encoding="utf-8"?>
<!-- DWXMLSource="testempty.xml" -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

  <xsl:strip-space elements="*" /> <!--HERE IS STRIP SPACE-->


  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Untitled Document</title>
    </head>

    <body>
    <xsl:for-each select="/group/item">
      <xsl:if test="CategoryName = ''"> <!--HERE IS THE TEST-->
        <p>Empty</p>          <!--IT WILL OUTPUT 'EMPTY' IF THE ELEMENT IS EMPTY-->
      </xsl:if>
    </xsl:for-each>
    </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

问题是,xsl:strip-space没有做好自己的工作.只有第2项的"CategoryName"通过"空"测试.

怎么了?

Dim*_*hev 1

显然,DeamWeaver 的 XSLT 处理器有一个错误。

这是获得所需结果的另一种方法:

代替

   <xsl:if test="CategoryName = ''">
Run Code Online (Sandbox Code Playgroud)

   <xsl:if test="not(normalize-space(CategoryName))">
Run Code Online (Sandbox Code Playgroud)