Share via


current 함수

현재 노드가 유일한 멤버인 노드 집합을 반환합니다.

node-set current()

설명

이 함수는 현재 노드가 유일한 멤버인 노드 집합을 반환합니다. 다른 식 내에서 발생하지 않는 식인 가장 바깥쪽 식에 대해 현재 노드는 항상 컨텍스트 노드와 같습니다. 그러므로

<xsl:value-of select="current()"/>

는 다음과 같습니다.

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

그러나 대괄호 안에서 현재 노드는 일반적으로 컨텍스트 노드와 다릅니다. 예를 들면 다음과 같습니다.

<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>

는 <glossary> 부모 요소가 있고 name 특성 값이 현재 노드의 ref 특성 값과 일치하는 모든 <item> 요소를 처리합니다. 이는 다음과 다릅니다.

<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>

이는 다음과 의미가 같습니다.

<xsl:apply-templates select="//glossary/item[@name=@ref]"/>

또한 <glossary> 부모 요소가 있고 name 특성 값과 ref 특성 값이 같은 모든 <item> 요소를 처리합니다.

예제

XML 파일(current.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="current.xsl" ?>
<nodes>
   <node>first</node>
   <node>1</node>
   <node>
      <obj>class</obj>
   </node>
</nodes>

XML 파일(current.xsl)

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

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

<xsl:template match="text()">
  <xsl:value-of select="current()"/>
</xsl:template>

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

</xsl:stylesheet>

출력

다음은 브라우저에 표시되는 형식이 지정된 출력입니다.

first

1

class

다음은 XSLT 프로세서의 출력입니다. 이 출력을 가져오려면 브라우저를 마우스 오른쪽 단추로 클릭하고 XSL 출력 보기 메뉴 항목을 선택합니다.

<?xml version="1.0" encoding="UTF-16"?>
<blockquote>
   <blockquote>first</blockquote>
   <blockquote>1</blockquote>
   <blockquote>
      <blockquote>class</blockquote>
   </blockquote>
</blockquote>

참고 항목

참조

XML 데이터 형식 참조