| Fonction string() | |
| Renvoie la valeur de chaîne de l'argument. | |
| Entrées | |
|
Un objet. L'objet est converti en chaîne, comme décrit dans la sous-section suivante. |
|
| Sortie | |
|
Une chaîne. L'argument d'entrée est converti en chaîne comme suit :
|
|
| Définie dans | |
|
XPath section 4.2, Fonctions Chaîne. |
|
| Exemple | |
|
Le document XML suivant a permis de tester la fonction string() :
<?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>
La fonction number() suivante a été testée avec plusieurs arguments :
<?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>
Les résultats sont les suivants :
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.
|
|