| not() 関数 | |
| パラメータの否定を返します。パラメータが既にブール値でない場合は、boolean() 関数で説明している規則を使用してブール値に変換されます。 | |
| 入力 | |
|
ブール値。より一般的には、ブール値を評価する XPath 式。 |
|
| 出力 | |
|
入力パラメータが true である場合は false、入力パラメータが false である場合は true。 |
|
| 定義先 | |
|
XPath 4.3 節「Boolean Functions」 |
|
| 例 | |
|
not() 関数を示すために、boolean() 関数で使用したのと同じスタイルシートと XML ドキュメントを使用します。この 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> このドキュメントを次のスタイルシートを使用して処理します。スタイルシートでは、not() を使用してすべての boolean() 関数呼び出しを否定します。
<?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 not() function:</xsl:text>
<xsl:value-of select="$newline"/>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean(true()))">
<xsl:text> "not(boolean(true()))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean(true()))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean(true))">
<xsl:text> "not(boolean(true))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean(true))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean('false'))">
<xsl:text> "not(boolean('false'))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean('false'))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean('7'))">
<xsl:text> "not(boolean('7'))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean('7'))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean(/true))">
<xsl:text> "not(boolean(/true))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean(/true))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="not(boolean(//true))">
<xsl:text> "not(boolean(//true))" returned true!</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> "not(boolean(//true))" returned false!</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
結果は次のとおりです。
Tests of the not() function:
"not(boolean(true()))" returned false!
"not(boolean(true))" returned true!
"not(boolean('false'))" returned false!
"not(boolean('7'))" returned false!
"not(boolean(/true))" returned true!
"not(boolean(//true))" returned false!
これらの結果は、boolean() 関数をテストしたときの結果と反対になります。 |
|