id()-Funktion  
Diese Funktion gibt den Knoten im Ausgangsbaum zurück, dessen ID-Attribut dem als Eingabe übergebenen Wert entspricht.
 
Eingaben

Ein Objekt. Ist das Eingabeobjekt eine Knotenmenge, so ist auch das Ergebnis eine Knotenmenge. Diese enthält das Ergebnis, das beim Anwenden der Funktion id() auf die String-Werte jedes Knotens der Knotenmenge im Argument entsteht. In der Regel ist das Argument ein anderer Knotentyp, der ein String ist (oder in einen String konvertiert worden ist). Dieser String wird dann als Such-Wert verwendet, nach dem alle Attribute vom Typ ID durchsucht werden.

Denken Sie daran, dass der XML-Datentyp ID dadurch eingeschränkt ist, dass nur ein Satz an Namen in allen Attributen als ID deklariert sein darf. Die XSLT-Funktion key() und das zugehörige Element <xsl:key> sind eine Antwort auf diese und andere Einschränkungen. Weitere Informationen hierzu finden Sie in der Beschreibung der Funktion key() und der Anweisung <xsl:key>.

 
Ausgabe

Eine Knotenmenge, die alle Knoten enthält, deren ID-Attribute den String-Werten der Eingabe-Knotenmenge entsprechen. In der Praxis handelt es sich bei dieser Knotenmenge um einen einzelnen Knoten, nämlich der Knoten, dessen ID-Attribut einem String-Wert entspricht.

 
Definition

XPath-Abschnitt 4.1, Funktionen auf Knotenmengen

 
Beispiel

Für das Beispiel wird die gekürzte Version eines Glossars verwendet:

<?xml version="1.0" ?>
<!DOCTYPE glossary SYSTEM "glossary.dtd">
<glossary>
  <glentry>
    <term id="applet">applet</term>
    <defn>
      An application program,
      written in the Java programming language, that can be 
      retrieved from a web server and executed by a web browser. 
      A reference to an applet appears in the markup for a web 
      page, in the same way that a reference to a graphics
      file appears; a browser retrieves an applet in the same 
      way that it retrieves a graphics file. 
      For security reasons, an applet's access rights are limited
      in two ways: the applet cannot access the filesystem of the 
      client upon which it is executing, and the applet's 
      communication across the network is limited to the server 
      from which it was downloaded. 
      Contrast with <xref refid="servlet"/>.
    </defn>
  </glentry>

  <glentry>
    <term id="servlet">servlet</term>
    <defn>
      An application program, written in the Java programming language, 
      that is executed on a web server. A reference to a servlet 
      appears in the markup for a web page, in the same way that a 
      reference to a graphics file appears. The web server executes
      the servlet and sends the results of the execution (if there are
      any) to the web browser. Contrast with <xref refid="applet" />.
    </defn>
  </glentry>
</glossary>

Hier das Stylesheet, das zur Auflösung der Referenzen verwendet wird:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <xsl:apply-templates select="glossary"/>
  </xsl:template>

  <xsl:template match="glossary">
    <html>
      <head>
        <title>
          <xsl:text>Glossary Listing </xsl:text>
        </title>
      </head>
      <body>
        <h1>
          <xsl:text>Glossary Listing </xsl:text>
        </h1>
        <xsl:apply-templates select="glentry"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="glentry">
    <p>
      <b>
        <a>
          <xsl:attribute name="name">
            <xsl:value-of select="term/@id" />
          </xsl:attribute>
        </a>

        <xsl:value-of select="term"/>
        <xsl:text>: </xsl:text>
      </b>
      <xsl:apply-templates select="defn"/>
    </p>
  </xsl:template>

  <xsl:template match="defn">
    <xsl:apply-templates 
     select="*|comment()|processing-instruction()|text()"/>
  </xsl:template>

  <xsl:template match="xref">
    <a>
      <xsl:attribute name="href">
        <xsl:text>#</xsl:text><xsl:value-of select="@refid"/>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="id(@refid)/@xreftext">
          <xsl:value-of select="id(@refid)/@xreftext"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="id(@refid)"/>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </xsl:template>

</xsl:stylesheet>

Das Stylesheet erzeugt die folgenden Ergebnisse:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Glossary Listing </title>
</head>
<body>
<h1>Glossary Listing </h1>
<p>
<b><a name="applet"></a>applet: </b>
      An application program,
      written in the Java programming language, that can be 
      retrieved from a web server and executed by a web browser. 
      A reference to an applet appears in the markup for a web 
      page, in the same way that a reference to a graphics
      file appears; a browser retrieves an applet in the same 
      way that it retrieves a graphics file. 
      
      For security reasons, an applet's access rights are limited
      in two ways: the applet cannot access the filesystem of the 
      client upon which it is executing, and the applet's 
      communication across the network is limited to the server 
      from which it was downloaded. 
      Contrast with <a href="#servlet">servlet</a>.
    </p>
<p>
<b><a name="servlet"></a>servlet: </b>
      An application program, written in the Java programming language, 
      that is executed on a web server. A reference to a servlet 
      appears in the markup for a web page, in the same way that a 
      reference to a graphics file appears. The web server executes
      the servlet and sends the results of the execution (if there are
      any) to the web browser. Contrast with <a href="#applet">applet</a>.
    </p>
</body>
</html>

Wie das Hyperlink-Dokument in einem Browser angezeigt wird, sehen Sie in Abbildung C-4.

Generiertes HTML-Glossar