id() 関数 | |
ID 属性が、入力として渡された値と一致するソースツリーのノードを返します。 | |
入力 | |
オブジェクト。入力オブジェクトがノードセットである場合、結果は、id() 関数をパラメータノードセットの各ノードの文字列値に適用した結果を含むノードセットとなります。通常、パラメータは他の何らかのノードタイプとなり、文字列となるか、文字列に変換されます。次に、この文字列は検索の値として使用され、タイプ ID のすべての属性が検索されます。 XML ID データタイプの制約として、すべての属性にわたる名前の 1 つのセットが、タイプ ID として宣言されます。XSLT key() 関数および関連の <xsl:key> 要素はこれをはじめ他の制約に対応しています。詳細については、key() 関数と <xsl:key> を参照してください。 |
|
出力 | |
タイプ ID の属性が、入力ノードセットの文字列値に一致するすべてのノードを含むノードセット。実際には、このノードセットは 1 つのノード、つまりタイプ ID の属性が文字列値に一致するノードです。 |
|
定義先 | |
XPath 4.1 節「ノードセット関数」 |
|
例 | |
この例では、前に説明した用語集の短いバージョンを使用します。 <?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> 参照を解決するために使用するスタイルシートを次に示します。 <?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> スタイルシートからは、次のような結果が生成されます。 <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> ハイパーリンクドキュメントは、ブラウザで表示されると図 C-4 のようになります。 生成された HTML 用語集 |