Share via


generate-id 함수

문서 순서에서 첫 번째인 node-set 인수에서 노드를 고유하게 식별하는 문자열을 반환합니다.

string generate-id(node-set?)

설명

고유 식별자는 ASCII 영숫자로 구성되어야 하며 영문자로 시작해야 합니다. 그러므로 이 문자열은 구문적으로 XML 이름입니다. 생성된 고유 식별자는 소스 문서에 지정된 고유 ID와 같을 수도 있습니다. node-set 인수가 비어 있을 경우 빈 문자열이 반환됩니다. 이 인수를 생략하면 기본값은 컨텍스트 노드입니다.

예제

XML 파일(data.xml)

<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
<catalog>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <title>XML Developer's Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>        
        <description>An in-depth look at creating applications with XML.</description>
    </book>
    <book id="bk102">
        <author>Ralls, Kim</author>
        <title>Midnight Rain</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-12-16</publish_date>
        <description>A former architect battles corporate zombies.</description>
    </book>
</catalog>

XSLT 파일(sample.xsl)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
  <xsl:template match="/">
        <html>
            <body>
                <xsl:for-each select="//book">
                    <button id="{generate-id(author)}" onclick="alert(this.id)">
                        <xsl:value-of select="author"/>
                    </button>
                </xsl:for-each>
            </body>
        </html>
  </xsl:template>
</xsl:stylesheet>

다음은 형식이 지정된 출력입니다.

generate_id 함수의 형식이 지정된 출력

Internet Explorer에서 왼쪽 단추를 클릭하면 경고 상자에 "IDAHAGJD"가 표시됩니다.

Internet Explorer에서 오른쪽 단추를 클릭하면 경고 상자에 "IDAPAGJD"가 표시됩니다.

ID 값은 런타임에 생성됩니다. 그러므로 특정 값은 각 변환 호출에서 달라질 수 있습니다.

다음은 프로세서 출력입니다.

<html>

<body><button id="IDAHAGJD" onclick="alert(this.id)">Gambardella, Matthew</button>

<button id="IDAPAGJD" onclick="alert(this.id)">Ralls, Kim</button></body>

</html>

참고 항목

참조

XML 데이터 형식 참조