これはxmlファイルです。 "CategoryName"要素のスペースとキャリッジリターンが意図されています。xsl:strip-spaceはキャリッジリターンを削除していません
<?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>
以下は、上記の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>
問題は、xsl:strip-space
はその仕事をしていません。アイテム2の「CategoryName」だけが「空の」テストに合格します。
どうしたのですか?
私は日食でこれをテストし、それが働きましたあなたが期待通りにそれを印刷しました。3 "空" – Weibo
私は使用しました。 Adobe Dreamweaverを使用すると、1つの空だけが表示されます。 – user1535147
可能な複製:http://stackoverflow.com/questions/1134318/xslt-xslstrip-space-does-not-work – K3N