--- title: Basic Example slug: Web/API/XSLTProcessor/Basic_Example translation_of: Web/API/XSLTProcessor/Basic_Example original_slug: XSLT_in_Gecko/Basic_Example ---

기본 예

이 첫 예는 브라우저에서 XSLT 변환 설정의 기본을 보여준다. 이 예는 Article에 대한 정보(Title, Author 목록과 Body 글)를 포함한 XML 문서를 얻어 그것을 사람이 읽을 수 있는 형식으로 나타낸다.

그림1은 기본 XSLT예의 소스를 보여준다. XML문서(example.xml)은 글의 정보를 포함한다. ?xml-stylesheet? 처리명령을 써서, 그것의 href 속성을 통해 XSLT 스타일쉬트(example.xsl)에 연결한다.

XSLT 스타일쉬트는 xsl:stylesheet 요소로 시작하는데, 이것은 최종 출력을 생성하는데 쓰이는 모든 템플리트를 포함한다. 그림1의 예는 템플리트 2개를 가진다 - 하나는 root 노드에 하나는 Author 노드에 대응한다. root 노드에 대응하는 템플리트는 글의 제목을 출력하고 Authors 노드의 자식노드인 Author 노드에 대응하는 모든 템플리트를 처리하기 위해 말한다.

그림1 : 간단한 XSLT예

XML 문서 (example.xml) :

  <?xml version="1.0"?>
  <?xml-stylesheet type="text/xsl" href="example.xsl"?>
  <Article>
    <Title>My Article</Title>
    <Authors>
      <Author>Mr. Foo</Author>
      <Author>Mr. Bar</Author>
    </Authors>
    <Body>This is my article text.</Body>
  </Article>

XSL 스타일쉬트 (example.xsl) :

  <?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="/">
      Article - <xsl:value-of select="/Article/Title"/>
      Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
    </xsl:template>

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

  </xsl:stylesheet>

브라우저 출력:

  Article - My Article
  Authors:
  - Mr. Foo
  - Mr. Bar
{{ languages( { "en": "en/XSLT_in_Gecko/Basic_Example" } ) }}