XSLT <xsl:키>
❮ 완전한 XSLT 요소 참조
정의 및 사용
<xsl:key> 요소는 key() 함수와 함께 스타일 시트에서 사용할 수 있는 명명된 키를 선언하는 최상위 요소입니다.
참고: 키가 고유할 필요는 없습니다!
통사론
<xsl:key
name="name"
match="pattern"
use="expression"/>
속성
Attribute | Value | Description |
---|---|---|
name | name | Required. Specifies the name of the key |
match | pattern | Required. Defines the nodes to which the key will be applied |
use | expression | Required. The value of the key for each of the nodes |
실시예 1
"persons.xml"이라는 XML 파일이 있다고 가정합니다.
<persons>
<person name="Tarzan" id="050676"/>
<person name="Donald" id="070754"/>
<person name="Dolly" id="231256"/>
</persons>
다음과 같이 XSL 파일에서 키를 정의할 수 있습니다.
<xsl:key name="preg" match="person" use="@id"/>
id="050676"인 사람을 찾으려면 다음을 작성하십시오(XSL 파일에서).
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="preg" match="person" use="@id"/>
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="key('preg','050676')">
<p>
Id: <xsl:value-of select="@id"/><br />
Name: <xsl:value-of select="@name"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
❮ 완전한 XSLT 요소 참조