<html>
<head>
<title>id()-Funktion</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Beschreibung">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">id()-Funktion</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Diese Funktion gibt den Knoten im Ausgangsbaum zur&uuml;ck, dessen ID-Attribut dem als Eingabe &uuml;bergebenen Wert entspricht. </td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Eingaben</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Ein Objekt. Ist das Eingabeobjekt eine Knotenmenge, so ist auch das Ergebnis eine Knotenmenge. Diese enth&auml;lt das Ergebnis, das beim Anwenden der Funktion <span class="LITERAL">id()</span> 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. </p>
<p>Denken Sie daran, dass der XML-Datentyp <span class="LITERAL">ID</span> dadurch eingeschr&auml;nkt ist, dass nur ein Satz an Namen in allen Attributen als <span class="LITERAL">ID</span> deklariert sein darf. Die XSLT-Funktion <span class="LITERAL">key()</span> und das zugeh&ouml;rige Element <span class="LITERAL">&lt;xsl:key&gt;</span> sind eine Antwort auf diese und andere Einschr&auml;nkungen. Weitere Informationen hierzu finden Sie in der Beschreibung der Funktion <span class="LITERAL">key()</span> und der Anweisung <span class="LITERAL">&lt;xsl:key&gt;</span>.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Ausgabe</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Eine Knotenmenge, die alle Knoten enth&auml;lt, deren <span class="LITERAL">ID</span>-Attribute den String-Werten der Eingabe-Knotenmenge entsprechen. In der Praxis handelt es sich bei dieser Knotenmenge um einen einzelnen Knoten, n&auml;mlich der Knoten, dessen <span class="LITERAL">ID</span>-Attribut einem String-Wert entspricht. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Definition</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XPath-Abschnitt 4.1, Funktionen auf Knotenmengen</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Beispiel</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>F&uuml;r das Beispiel wird die gek&uuml;rzte Version eines Glossars verwendet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0" ?&gt;
&lt;!DOCTYPE glossary SYSTEM "glossary.dtd"&gt;
&lt;glossary&gt;
  &lt;glentry&gt;
    &lt;term id="applet"&gt;applet&lt;/term&gt;
    &lt;defn&gt;
      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 &lt;xref refid="servlet"/&gt;.
    &lt;/defn&gt;
  &lt;/glentry&gt;

  &lt;glentry&gt;
    &lt;term id="servlet"&gt;servlet&lt;/term&gt;
    &lt;defn&gt;
      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 &lt;xref refid="applet" /&gt;.
    &lt;/defn&gt;
  &lt;/glentry&gt;
&lt;/glossary&gt;</pre></span>
<p>Hier das Stylesheet, das zur Aufl&ouml;sung der Referenzen verwendet wird:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
&lt;xsl:output method="html" indent="yes"/&gt;
&lt;xsl:strip-space elements="*"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:apply-templates select="glossary"/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="glossary"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;
          &lt;xsl:text&gt;Glossary Listing &lt;/xsl:text&gt;
        &lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;h1&gt;
          &lt;xsl:text&gt;Glossary Listing &lt;/xsl:text&gt;
        &lt;/h1&gt;
        &lt;xsl:apply-templates select="glentry"/&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="glentry"&gt;
    &lt;p&gt;
      &lt;b&gt;
        &lt;a&gt;
          &lt;xsl:attribute name="name"&gt;
            &lt;xsl:value-of select="term/@id" /&gt;
          &lt;/xsl:attribute&gt;
        &lt;/a&gt;
<!--<?troff .Nd 10?>-->
        &lt;xsl:value-of select="term"/&gt;
        &lt;xsl:text&gt;: &lt;/xsl:text&gt;
      &lt;/b&gt;
      &lt;xsl:apply-templates select="defn"/&gt;
    &lt;/p&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="defn"&gt;
    &lt;xsl:apply-templates 
     select="*|comment()|processing-instruction()|text()"/&gt;
  &lt;/xsl:template&gt;

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

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Das Stylesheet erzeugt die folgenden Ergebnisse:</p>
<span class="PROGRAMLISTING"><pre>
&lt;html&gt;
&lt;head&gt;
&lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;Glossary Listing &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Glossary Listing &lt;/h1&gt;
&lt;p&gt;
&lt;b&gt;&lt;a name="applet"&gt;&lt;/a&gt;applet: &lt;/b&gt;
      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. 
      <!--<?troff .Nd 10?>-->
      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 &lt;a href="#servlet"&gt;servlet&lt;/a&gt;.
    &lt;/p&gt;
&lt;p&gt;
&lt;b&gt;&lt;a name="servlet"&gt;&lt;/a&gt;servlet: &lt;/b&gt;
      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 &lt;a href="#applet"&gt;applet&lt;/a&gt;.
    &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></span>
<p>Wie das Hyperlink-Dokument in einem Browser angezeigt wird, sehen Sie in <link linkend="xslt-appc-c4">Abbildung C-4</link>.</p>
<figure id="xslt-appc-c4" label="C-4">
        <p class="TITLE">Generiertes HTML-Glossar</p>
        <graphic depth="299" width="481" fileref="figs/xslt.ac04.gif"/></figure>
</td>
</tr>
</table>
</div>
</body>
</html>
