XSLT <xsl:template> 요소
정의 및 사용법
<xsl:template> 요소는 특정 노드에 매칭되었을 때 적용할 규칙을 포함합니다.
match属性는 템플릿을 특정 XML 요소에 연결하는 데 사용됩니다. match属性는 XML 문서의 전체 브랜치에 대한 템플릿을 정의하는 데도 사용될 수 있습니다(예: match="/"는 전체 문서를 정의합니다).
주의:<xsl:template>는 최상위 요소(top-level element)입니다.
문법
<xsl:template name="name" match="pattern" mode="mode" priority="number"> <!-- Content:(<xsl:param>*,template) --> </xsl:template>
속성
속성 | 값 | 설명 |
---|---|---|
name | name |
선택 사항. 템플릿에 대한 이름을 정의. 주의: 이属性을 제외하고는 match属性을 설정해야 합니다. |
match | pattern |
선택 사항. 템플릿의 매칭 모드. 주의: 이属性을 제외하고는 name属性을 설정해야 합니다. |
mode | mode | 선택 사항. 템플릿에 대한 모드를 정의. |
priority | number | 선택 사항. 템플릿의 우선 순위 번호. |
예시
예제 1
<?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> <h2>My CD Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> 제목: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /> </xsl:template> <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet>