Đây là tệp xml. Không gian và vận chuyển trở lại trong phần tử "CategoryName" được dự định.xsl: không gian dải không phải là loại bỏ trở lại vận chuyển
<?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>
Sau đây là tệp XSLT cho tệp XML ở trên. Những gì nó là giả sử để làm là nó sẽ xóa tất cả các không gian trống trong phần tử "CategoryName". Sau đó, nó sẽ kiểm tra xem "CategoryName" có trống hay không.
<?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>
Vấn đề là, xsl:strip-space
không hoạt động. Chỉ "CategoryName" của Mục 2 vượt qua bài kiểm tra "trống".
Điều gì là sai?
tôi thử nghiệm này trên nhật thực của tôi, nó làm việc như bạn mong đợi. Nó in 3 "rỗng" – Weibo
tôi đã sử dụng Adobe Dreamweaver và nó chỉ hiển thị một Empty. – user1535147
Có thể trùng lặp: http://stackoverflow.com/questions/1134318/xslt-xslstrip-space-does-not-work – K3N