XSLT <xsl:변수>
❮ 완전한 XSLT 요소 참조
정의 및 사용
<xsl:variable> 요소는 지역 또는 전역 변수를 선언하는 데 사용됩니다.
참고: 변수는 최상위 요소로 선언된 경우 전역 변수이고 템플릿 내에서 선언된 경우 지역 변수입니다.
참고: 변수 값을 설정한 후에는 해당 값을 변경하거나 수정할 수 없습니다!
팁: <xsl:variable> 요소의 내용이나 select 속성으로 변수에 값을 추가할 수 있습니다!
통사론
<xsl:variable
name="name"
select="expression">
<!-- Content:template -->
</xsl:variable>
속성
Attribute | Value | Description |
---|---|---|
name | name | Required. Specifies the name of the variable |
select | expression | Optional. Defines the value of the variable |
실시예 1
select 속성이 있는 경우 <xsl:variable> 요소는 콘텐츠를 포함할 수 없습니다. 선택 속성에 리터럴 문자열이 포함된 경우 문자열은 따옴표 안에 있어야 합니다. 다음 두 예에서는 "red" 값을 "color" 변수에 할당합니다.
<xsl:variable name="color" select="'red'" />
<xsl:variable name="color" select='"red"' />
실시예 2
<xsl:variable> 요소가 이름 속성만 포함하고 내용이 없는 경우 변수 값은 빈 문자열입니다.
<xsl:variable name="j" />
실시예 3
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable
name="header">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
</xsl:variable>
<xsl:template
match="/">
<html>
<body>
<table border="1">
<xsl:copy-of select="$header" />
<xsl:for-each
select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ 완전한 XSLT 요소 참조