Fonction id() | |
Renvoie le nœud de l'arborescence source dont l'attribut ID correspond à la valeur transmise comme entrée. | |
Entrées | |
Un objet. Si l'objet d'entrée est un ensemble de nœuds, le résultat représente un ensemble de nœuds contenant le résultat de l'application de la fonction id() sur la valeur de chaîne de chaque nœud de l'ensemble de nœuds de l'argument. En règle générale, l'argument correspond à un autre type de nœud représentant (ou converti en) une chaîne. Cette chaîne est alors utilisée comme valeur de recherche lors de la recherche de tous les attributs de type ID. Une des limites du type de données ID XML à ne pas oublier est qu'un simple ensemble de noms pour tous les attributs est déclaré comme étant de type ID. La fonction key() de XSLT et l'élément <xsl:key> qui lui est associé traitent ce problème ainsi que d'autres limitations ; consultez la fonction key() et l'élément <xsl:key> pour de plus amples informations. |
|
Sortie | |
Un ensemble de nœuds contenant tous les nœuds dont les attributs de type ID correspondent aux valeurs de chaîne de l'ensemble de nœuds d'entrée. Concrètement, cet ensemble de nœuds est un nœud unique, le nœud dont l'attribut de type ID correspond à une valeur de chaîne. |
|
Définie dans | |
XPath section 4.1, Fonctions Ensemble de nœuds. |
|
Exemple | |
L'exemple suivant se sert de la version de glossaire raccourcie mentionnée précédemment : <?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> La feuille de style utilisée pour résoudre les références est la suivante : <?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> Les résultats suivants ont été générés par la feuille de style : <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> Une fois affiché dans un navigateur, le document hyperlié ressemble à la Figure C-4. Glossaire HTML généré |