<html>
<head>
<title>string-length()-Funktion</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Beschreibung">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">string-length()-Funktion</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Diese Funktion gibt die Anzahl der Zeichen in dem String zur&uuml;ck, der als Argument an die Funktion &uuml;bergeben worden ist. Ohne Argument wird der Kontextknoten in einen String konvertiert und seine L&auml;nge zur&uuml;ckgegeben.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Eingaben</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Ein optionaler String. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Ausgabe</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Die Anzahl der im String definierten Zeichen. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Definition</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XPath-Abschnitt 4.2, Zeichenkettenfunktionen.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Beispiel</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Das folgende Beispiel demonstriert die Ergebnisse, wenn die Funktion <span class="LITERAL">string-length()</span> auf eine Vielzahl verschiedener Argumenttypen angewendet wird. F&uuml;r das Beispiel wird das folgende XML-Dokument verwendet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;test&gt;
  &lt;p&gt;This is a test XML document used by several 
  of our sample stylesheets.&lt;/p&gt;
  &lt;question&gt;
    &lt;text&gt;When completed, the Eiffel Tower was the 
    tallest building in the world.&lt;/text&gt;
    &lt;true&gt;You're correct!  The Eiffel Tower was the 
    world's tallest building until 1930.&lt;/true&gt;
    &lt;false&gt;No, the Eiffel Tower was the world's 
    tallest building for over 30 years.&lt;/false&gt;
  &lt;/question&gt;
  &lt;question&gt;
    &lt;text&gt;New York's Empire State Building knocked 
    the Eiffel Tower from its pedestal.&lt;/text&gt;
    &lt;true&gt;No, that's not correct.&lt;/true&gt;
    &lt;false&gt;Correct!  New York's Chrysler Building, 
    completed in 1930, became the world's tallest.&lt;/false&gt;
  &lt;/question&gt;
&lt;/test&gt;</pre></span>
<p>Das Dokument wird mit dem folgenden Stylesheet verarbeitet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

<!--<?troff .Nd 10?>-->
  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;Tests of the string-length() function:&lt;/xsl:text&gt;

    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   string-length(/test)=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="string-length(/test)"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   string-length(/true)=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="string-length(/true)"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   string-length(//true)=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="string-length(//true)"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   string-length(//test|//true|//text)=&lt;/xsl:text&gt;
    &lt;xsl:value-of select="string-length(//test|//true|//text)"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:for-each select="/test/question"&gt;
      &lt;xsl:text&gt;   Question #&lt;/xsl:text&gt;
      &lt;xsl:value-of select="position()"/&gt;
      &lt;xsl:text&gt; contains &lt;/xsl:text&gt;
      &lt;xsl:value-of select="string-length()"/&gt;
      &lt;xsl:text&gt; characters.&lt;/xsl:text&gt;
      &lt;xsl:value-of select="$newline"/&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Hier die Ergebnisse der Transformation:</p>
<span class="PROGRAMLISTING"><pre>

Tests of the string-length() function:

   string-length(/test)=522
   string-length(/true)=0
   string-length(//true)=78
   string-length(//test|//true|//text)=522

   Question #1 contains 239 characters.
   Question #2 contains 203 characters.
</pre></span>
<p>Beim Aufruf der Funktion <span class="LITERAL">string-length()</span> ohne Argumente wurde der Kontextknoten in einen String konvertiert und dann die L&auml;nge dieses Strings zur&uuml;ckgegeben. Die zwei <span class="LITERAL">&lt;question&gt;</span>-Elemente wurden innerhalb des <span class="LITERAL">&lt;xsl:for-each&gt;</span>-Elements so behandelt. </p>
</td>
</tr>
</table>
</div>
</body>
</html>
