boolean() 関数 | |
パラメータをブール値に変換します。 | |
入力 | |
オブジェクト。オブジェクトはブール値に変換されます。この変換については、後のサブセクションで説明します。 |
|
出力 | |
入力オブジェクトに対応するブール値。オブジェクトは次のようにブール値に変換されます。
|
|
定義先 | |
XPath 4.3 節「Boolean Functions」 |
|
例 | |
次の例では、さまざまなパラメータタイプに対して boolean() 関数を呼び出した結果を示します。この XML ドキュメントは次のとおりです。 <?xml version="1.0"?> <test> <p>This is a test XML document used by several of our sample stylesheets.</p> <question> <text>When completed, the Eiffel Tower was the tallest building in the world.</text> <true>Yes! The Eiffel Tower was the world's tallest building until 1932, when New York's Empire State Building opened. </true> <false>No, the Eiffel Tower was the world's tallest building for over 30 years.</false> </question> </test> 次のスタイルシートを使用してこのドキュメントを処理します。 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="$newline"/> <xsl:text>Tests of the boolean() function:</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean(true())"> <xsl:text> "boolean(true())" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean(true())" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean(true)"> <xsl:text> "boolean(true)" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean(true)" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean('false')"> <xsl:text> "boolean('false')" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean('false')" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean('7')"> <xsl:text> "boolean('7')" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean('7')" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean(/true)"> <xsl:text> "boolean(/true)" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean(/true)" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$newline"/> <xsl:choose> <xsl:when test="boolean(//true)"> <xsl:text> "boolean(//true)" returned true!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text> "boolean(//true)" returned false!</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> 結果は次のとおりです。 Tests of the boolean() function: "boolean(true())" returned true! "boolean(true)" returned false! "boolean('false')" returned true! "boolean('7')" returned true! "boolean(/true)" returned false! "boolean(//true)" returned true! その他の例および詳細については、第 4 章 4.2.1.2 節を参照してください。 |