XSLT current() 함수

정의와 사용법

current() 함수는 단지 현재 노드를 포함하는 노드 집합을 반환합니다. 일반적으로, 현재 노드는 상황 노드와 같습니다.

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

равен

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

그러나, 하나의 차이점이 있습니다. 아래의 XPath 표현식을 보세요: "catalog/cd". 이 표현식은 현재 점의 <catalog> 자식 노드를 선택한 후, <catalog> 노드의 <cd> 자식 노드를 선택합니다. 이는 계산의 각 단계에서 "."이 다른 의미를 가진다는 것을 의미합니다.

아래의 이 줄:

<xsl:apply-templates select="//cd[@title=current()/@ref]"/>

title 속성의 값이 현재 점의 ref 속성의 값과 같은 모든 cd 요소를 처리합니다.

이와 다릅니다:

<xsl:apply-templates select="//cd[@title=./@ref]"/>

이 회는 title 속성과 ref 속성이 같은 값을 가진 모든 cd 요소를 처리합니다.

문법

node-set current()

예제

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
  <xsl:for-each select="catalog/cd/artist">
    현재 노드: <xsl:value-of select="current()"/>
    <br />
  </xsl:for-each>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

XML 파일 확인,XSL 파일 확인,결과 확인.