XSLT½Ì³Ì

XSLT <xsl:preserve-space>  Óë <xsl:strip-space> ÔªËØs
2007-3-30

·µ»Ø

Definition and Usage
¶¨ÒåºÍÓ÷¨

The <xsl:preserve-space> element is used to define the elements for which white space should be preserved.
<xsl:preserve-space>ÔªËØµÄ×÷ÓÃÊÇ£º¶¨ÒåÐèÒª±£Áô¿Õ°×ÐзûµÄÔªËØ¡£

The <xsl:strip-space> element is used to define the elements for which white space should be removed.
<xsl:strip-space>ÔªËØµÄ×÷ÓÃÊÇ£º¶¨ÒåÐèҪɾ³ý¿Õ°×ÐзûµÄÔªËØ¡£

Note: Preserving white space is the default setting, so using the <xsl:preserve-space> element is only necessary if  the <xsl:strip-space> element is used.
×¢Ò⣺±£Áô¿Õ°×ÐзûʱĬÈϵÄÉèÖã¬Òò´Ë£¬Èç¹ûʹÓÃÁË<xsl:strip-space>ÔªËØ£¬ÄÇô¾Í±ØÐëʹÓÃ<xsl:preserve-space>ÔªËØ¡£

Note: The <xsl:preserve-space> element and the <xsl:strip-space> element are top-level elements.
×¢Ò⣺ <xsl:preserve-space> ÔªËØºÍ<xsl:strip-space>ÔªËØ¶¼ÊǶ¥¼¶ÔªËØ¡£


Syntax
Óï·¨

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

Attributes
ÊôÐÔ

ÊôÐÔ Öµ ÃèÊö
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
×¢Ò⣺Õâ¸öÁбí¿ÉÒÔ°üº¬"*"ºÍǰ׺£º*"£¬Òò´Ë£¬ËùÓÐÔªËØ»òÀ´×ÔÓÚÌØ¶¨ÃüÃû¿Õ¼äµÄËùÓÐÔªËØ¶¼¿ÉÒÔ°üº¬ÆäÖÐ

Example 1
°¸Àý1

In the example below we preserve white space nodes for title and artist elements, and remove white space nodes for country, company, price, and year elements:
ÔÚÏÂÃæµÄ°¸ÀýÖУ¬ÎÒÃÇΪtitleºÍartistÔªËØ±£ÁôÁ˿հ×Ðзû½Úµã£¬É¾³ýÁËcountry¡¢company¡¢priceÒÔ¼°yearÔªËØµÄ¿Õ°×Ðзû½Úµã£º

<?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>

 

·µ»Ø