Share via


<xsl:text> 요소

스타일시트로부터 텍스트 노드를 생성합니다. 출력에 공백 전용 노드가 유지됩니다.

<xsl:text
  disable-output-escaping = "yes" | "no">
</xsl:text>

특성

  • disable-output-escaping
    기본값은 "no"입니다. 값이 "yes"인 경우 <xsl:text> 요소를 인스턴스화하여 생성된 텍스트 노드가 이스케이프 없이 출력됩니다. 예를 들어, 다음은 단일 문자 "<"를 생성합니다.

    <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
    

    참고

    disable-output-escaping="yes"를 사용하여 올바르지 않은 형식의 문서를 생성할 수 있으므로 주의해서 사용해야 합니다.어떤 경우에는 올바르지 않은 형식의 출력으로 인해 오류가 생길 수 있습니다.예를 들어, XML 문서에서 transformNodeToObject를 실행하려면 결과의 형식이 올바르게 지정되어야 하므로 disable-output-escaping이 문서의 올바른 형식에 영향을 줄 경우 완료되지 않을 수 있습니다.disable-output-escaping="yes"는 잠재적인 위험성을 이해할 경우에만 사용할 수 있는 고급 기능입니다.

요소 정보

발생 횟수

제한 없음

부모 요소

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:otherwise, xsl:message, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, 출력 요소

자식 요소

자식 요소 없음

설명

스타일시트에서 <xsl:text>를 사용하거나 사용하지 않고도 리터럴 결과 트리에 텍스트를 생성할 수 있습니다. 그러나 이 요소를 사용할 경우 스타일시트에서 만든 공백을 적절히 제어할 수 있습니다. 예를 들어, 스타일시트를 알아보기 쉽도록 템플릿에서 한 줄에 요소 하나씩 쓰고 몇몇 줄은 들여쓸 수 있습니다. 그러면 공백이 템플릿 규칙의 일부로 도입됩니다. 변환할 때 이러한 작업이 적절하지 않을 수도 있습니다.

때때로 두 데이터 값을 구분하기 위해 공백 문자를 넣을 수 있습니다. 이 작업을 수행하려면 <xsl:text> 요소를 사용합니다. <xsl:text> 안에 포함된 공백은 결과 트리에 출력됩니다. 그러므로 다음

<xsl:template match="a-node">
   <xsl:text>
   </xsl:text>
</xsl:template>

템플릿은 항상 결과 트리에 새 줄 텍스트 노드를 출력합니다. 그러나 공백 전용 텍스트 노드가 <xsl:text> 안에 포함되지 않으면 결과 트리에서 제거됩니다. 아래 예제에서는 빈 <xsl:text/> 요소를 사용하여 이 작업을 수행하는 방법을 보여 줍니다.

예제

XML 파일(text.xml)

<?xml version="1.0"?>
<topic>
  <text>First line.</text>
  <text>Second line.</text>
  <text></text>
</topic>

XSLT 파일(text.xsl)

다음 스타일시트는 빈 <xsl:text/> 요소를 사용하여 템플릿 규칙에서 생성하는 공백 문자(공백, 줄 바꿈 및 탭)를 모두 제거합니다. 이 작업의 결과는 아래와 같이 형식이 지정된 출력으로 표시됩니다.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="text">
    <xsl:text/>"<xsl:value-of select="."/>"<xsl:text/>
  </xsl:template>
</xsl:stylesheet>

HTML 파일(text.htm)

다음 HTML 파일을 사용하여 XSLT 변환을 수행하고 결과를 확인할 수 있습니다.

<html>
  <head>
    <title></title>
  </head>
  <body onload="init()">
     <div><input type="text" id="xmlName" value="text.xml"></div>
     <div><input type="text" id="xslName" value="text.xsl"></div>
     <div><input type=button value="transform" onclick="trans();"></div>
     <div id="divErr"></div>
     <pre id="preRes" style="background:blue;color:gold"></pre>
  </body>

  <script language="javascript">
    function trans() 
    {
      xmlFile=xmlName.value;
      xslFile=xslName.value;
      if (xmlFile == "" || xslFile == "") 
      {
         divErr.innerHTML = "invalid xml/xsl file names.";
      }

      var xsl = new ActiveXObject("MSXML2.DOMDOCUMENT.6.0");
      var xml = new ActiveXObject("MSXML2.DOMDocument.6.0");
      xml.validateOnParse = false;
      xml.async = false;
      xml.load(xmlFile);
      if (xml.parseError.errorCode != 0)
        divErr.innerHTML = "XML Parse Error : " + xml.parseError.reason;

      xsl.async = false;
      xsl.load(xslFile);
      if (xsl.parseError.errorCode != 0)
        divErr.innerHTML = "XSL Parse Error : " + xsl.parseError.reason;

      try
      {
        res = xml.transformNode(xsl.documentElement);
        preRes.innerText = res;
      }
      catch(err)
      {
        divErr.innerHTML = "Transformation Error:"
               +err.number+"*"+err.description;
      }
    }
  </script>
</html>

실습

  1. 샘플 코드를 적절한 파일에 복사하고 해당 파일을 로컬 드라이브에 저장합니다.

  2. HTML 파일(text.htm)을 두 번 클릭합니다.

  3. 나타나는 웹 페이지에서 transform 단추를 클릭합니다.

출력

위의 XSLT 스타일시트를 그대로 사용하면 모든 텍스트 값은 출력의 단일 줄에서 처음부터 끝까지 조인됩니다.

"First line.""Second line."""

text 요소와 일치하는 템플릿에서 <xsl:text/> 요소를 모두 제거하면 출력은 다음과 같이 7개의 줄로 표시됩니다.

"First line."

"Second line."

""

템플릿에서 첫 번째 <xsl:text/> 요소만 제거하면 출력은 다음과 같이 4개의 줄로 표시됩니다.

"First line."

"Second line."

""

참고 항목

참조

<xsl:comment> 요소