string() 関数 | |
パラメータの文字列値を返します。 | |
入力 | |
オブジェクト。オブジェクトは、後のサブセクションで説明するように文字列に変換されます。 |
|
出力 | |
文字列。入力パラメータは次のように文字列に変換されます。
|
|
定義先 | |
XPath 4.2 節「文字列関数」 |
|
例 | |
string() 関数をテストするために使用する 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>You're correct! The Eiffel Tower was the world's tallest building until 1930.</true> <false>No, the Eiffel Tower was the world's tallest building for over 30 years.</false> </question> <question> <text>New York's Empire State Building knocked the Eiffel Tower from its pedestal.</text> <true>No, that's not correct.</true> <false>Correct! New York's Chrysler Building, completed in 1930, became the world's tallest.</false> </question> </test> さまざまなパラメータを使用して string() 関数をテストします。 <?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 string() function:</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:text> string(count(/test))=</xsl:text> <xsl:value-of select="string(count(/test))"/> <xsl:value-of select="$newline"/> <xsl:text> string(count(/test/question))=</xsl:text> <xsl:value-of select="string(count(/test/question))"/> <xsl:value-of select="$newline"/> <xsl:text> string('4')=</xsl:text> <xsl:value-of select="string('4')"/> <xsl:value-of select="$newline"/> <xsl:text> string(true())=</xsl:text> <xsl:value-of select="string(true())"/> <xsl:value-of select="$newline"/> <xsl:text> string(false())=</xsl:text> <xsl:value-of select="string(false())"/> <xsl:value-of select="$newline"/> <xsl:text> string(count(/test/question) > 5)=</xsl:text> <xsl:value-of select="string(count(/test/question) > 5)"/> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:text>Here are the string values of some <text> elements:</xsl:text> <xsl:value-of select="$newline"/> <xsl:for-each select="/test/question/text"> <xsl:text> </xsl:text> <xsl:value-of select="string(.)"/> <xsl:value-of select="$newline"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> このスタイルシートの結果は次のとおりです。 Tests of the string() function: string(count(/test))=1 string(count(/test/question))=2 string('4')=4 string(true())=true string(false())=false string(count(/test/question) > 5)=false Here are the string values of some <text> elements: When completed, the Eiffel Tower was the tallest building in the world. New York's Empire State Building knocked the Eiffel Tower from its pedestal. |