Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT <XSL: Preserve-Space> and <XSL: Strip-Space> Elements


May 28, 2021 XSL T


Table of contents


XSLT and lt;xsl: preserve-space-gt; and slt;xsl:strip-space-gt; elements

In XSLT, both elements are related to blank elements, refer to the contents of this section.


XSLT <xsl:preserve-space> 和 <xsl:strip-space> elements Complete XSLT element reference manual

Definitions and usages

The element is used to define elements that remain blank.

The element is used to define the element that removes the blank space.

Note: Keeping white space is the default setting, so it is only necessary to use the .lt;xsl:strip-space-gt; element.

Note: The elements are both top-level elements (top-level element) and the elements of the .lt;xsl:strip-space-gt;


Grammar

<xsl:preserve-space elements="list-of-element-names"/>

<xsl:strip-space elements="list-of-element-names"/>

Property

Attributes value describe
elements list-of-element-names

Required.A list of spaces separated by a space specify the reservation / delete blank element.

Notice: In the list, "*" and "prefix: *" can be included, so you can join all elements or all elements from a specific namespace.

Instance 1

In this example, we reserved blank nodes for the title and artist elements and removed them from the country, company, price, and year elements:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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>

XSLT <xsl:preserve-space> 和 <xsl:strip-space> elements Complete XSLT element reference manual