XSLT <xsl:apply-templates>
❮ 완전한 XSLT 요소 참조
정의 및 사용
<xsl:apply-templates> 요소는 현재 요소 또는 현재 요소의 자식 노드에 템플릿을 적용합니다.
<xsl:apply-templates> 요소에 select 속성을 추가하면 속성 값과 일치하는 자식 요소만 처리됩니다. select 속성을 사용하여 자식 노드가 처리되는 순서를 지정할 수 있습니다.
통사론
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
속성
Attribute | Value | Description |
---|---|---|
select | expression | Optional. Specifies the nodes to be processed. An asterisk selects the entire node-set. If this attribute is omitted, all child nodes of the current node will be selected |
mode | name | Optional. If there are multiple ways of processing defined for the same element, distinguishes among them |
실시예 1
문서의 각 제목 요소 주위에 단일 h1 요소를 래핑합니다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
실시예 2
메시지의 자식인 모든 제목 요소 주위에 단일 h1 요소를 래핑합니다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
실시예 3
mode 속성이 "big"로 설정된 메시지의 모든 자식 노드 주위에 단일 h1 요소를 래핑합니다.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
❮ 완전한 XSLT 요소 참조