string()-Funktion | |
Diese Funktion liefert den String-Wert des Arguments. | |
Eingaben | |
Ein Objekt. Das Objekt wird wie unten beschrieben in einen String konvertiert. |
|
Ausgabe | |
Ein String. Das Eingabeargument wird wie folgt in einen String konvertiert:
|
|
Definition | |
XPath-Abschnitt 4.2, Zeichenkettenfunktionen. |
|
Beispiel | |
Hier das XML-Dokument, mit dem die Funktion string() erprobt werden soll: <?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> Die Funktion string() wird mit einer Vielzahl von Argumenten getestet: <?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> Hier die Ergebnisse der Transformation: 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. |