다음을 통해 공유


id 함수

고유 ID로 요소를 선택합니다.

node-set id(object)

주의

인수가 노드 집합 형식인 경우 결과는 노드 집합 인수에서 각 노드의 문자열 값에 id()를 적용한 결과를 합한 것입니다.

인수가 그 외의 형식인 경우 문자열로 변환된 다음 공백으로 구분된 토큰 목록으로 분할됩니다. 공백은 프로덕션과 일치하는 임의의 문자 시퀀스입니다. 결과는 고유 ID가 목록의 토큰과 일치하는 컨텍스트 노드와 같은 문서에 있는 요소가 포함된 노드 집합입니다.

예제

XML 파일(test.xml)

<?xml version="1.0"?>
<!DOCTYPE test [
  <!ELEMENT test (x+)>
  <!ELEMENT x (x+| y+)>
  <!ATTLIST x
     a ID #REQUIRED>
  <!ELEMENT y ANY>
]>
<test>
    <x a="a11">
      <x a="a21">
        <x a="a31">
          <y>y31</y>
          <y>y32</y>
        </x>
      </x>
    </x>
    <x a="a12">
      <x a="a22">
        <y>y21</y>
        <y>y22</y>
      </x>
    </x>
    <x a="a13">
      <y>y11</y>
      <y>y12</y>
    </x>
    <x a="a14">
      <y>y03</y>
      <y>y04</y>
    </x>
</test>

XSLT 파일(test.xsl)

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

  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <!-- suppress text nodes not covered in subsequent        template rule -->
  <xsl:template match="text()"/>

  <xsl:template match="*">
    <xsl:element name="{name()}">
      <xsl:apply-templates select="*|@*"/>
      <xsl:if test="text()">
         <xsl:value-of select="."/>
      </xsl:if>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:attribute name="{name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="/test">
    <xsl:apply-templates select="id('a21') "/>
and 
    <xsl:apply-templates select="id('a11')//y[1]"/>
  </xsl:template>

</xsl:stylesheet>

출력

XSLT 스타일시트를 위의 XML 파일에 적용할 경우 다음 노드 집합이 생성됩니다.

<x a="a21">

<x a="a31">

<y>y31</y>

<y>y32</y>

</x>

</x>

and

<y>y31</y>

참고 항목

참조

XML 데이터 형식 참조