XSLT <xsl:preserve-space>와 <xsl:strip-space> 요소

정의와 사용법

<xsl:preserve-space> 요소는 공백을 유지하는 요소를 정의합니다.

<xsl:strip-space> 요소는 공백을 제거할 요소를 정의합니다。

주의:공백 유지는 기본 설정이므로 <xsl:strip-space> 요소를 사용하여 공백을 제거할 때에만 <xsl:preserve-space> 요소를 사용해야 합니다。

주의:<xsl:preserve-space> 요소와 <xsl:strip-space> 요소는 최상위 요소(top-level element)입니다。

문법

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

속성

속성 설명
elements list-of-element-names

필수. 공백으로 구분된 요소 목록은 공백을 유지/삭제할 요소를 정의합니다。

주의: 목록에 "*"와 "prefix:*"를 포함할 수 있어 모든 요소나 특정 이름 공간의 모든 요소를 추가할 수 있습니다。

예시

예제 1

본 예제에서는 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>