XSLT <xsl: strip-space>
❮ Toàn bộ tham chiếu phần tử XSLT
Định nghĩa và Cách sử dụng
Phần tử <xsl: strip-space> được sử dụng để xác định các phần tử cần loại bỏ khoảng trắng.
Lưu ý: Duy trì khoảng trắng là cài đặt mặc định, vì vậy việc sử dụng phần tử <xsl: keep-space> chỉ cần thiết nếu phần tử <xsl: strip-space> được sử dụng.
Lưu ý: Phần tử <xsl: keep-space> và phần tử <xsl: strip-space> là các phần tử cấp cao nhất.
Cú pháp
<xsl:preserve-space elements="list-of-element-names"/>
<xsl:strip-space elements="list-of-element-names"/>
Thuộc tính
Attribute | Value | Description |
---|---|---|
elements | list-of-element-names | Required. A white space separated list of element names for which white space should be preserved/removed. Note: The list can also contain "*" and "prefix:*" so that all elements or all elements from a particular namespace can be joined |
ví dụ 1
Trong ví dụ dưới đây, chúng tôi bảo tồn các nút khoảng trắng cho các yếu tố tiêu đề và nghệ sĩ, đồng thời xóa các nút khoảng trắng cho các yếu tố quốc gia, công ty, giá và năm:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="country company price year" />
<xsl:preserve-space elements="title artist" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd">
<p>
<xsl:value-of select="title" /><br />
<xsl:value-of select="artist" /><br />
<xsl:value-of select="country" /><br />
<xsl:value-of select="company" /><br />
<xsl:value-of select="price" /><br />
<xsl:value-of select="year" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ Toàn bộ tham chiếu phần tử XSLT