normalize-space()-Funktion | |
Mit dieser Funktion lässt sich zusätzlicher Leerraum aus dem String im Argument entfernen. | |
Eingaben | |
Ein optionaler String. Wird kein Argument angegeben, verwendet die Funktion normalize-space() den String-Wert des Kontextknotens. |
|
Ausgabe | |
Der Argument-String, aus dem Leerräume wie folgt entfernt worden sind:
|
|
Definition | |
XPath-Abschnitt 4.2, Zeichenkettenfunktionen |
|
Beispiel | |
Hier ein kurzes Beispiel, das veranschaulicht, wie normalize-space() funktioniert: <?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:variable name="testString"> <xsl:text> This is a string with lots of whitespace. </xsl:text> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="$newline"/> <xsl:text>Tests of the normalize-space() function:</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:text> normalize-space(' Hello, World!')="</xsl:text> <xsl:value-of select="normalize-space(' Hello, World!')"/> <xsl:text>"</xsl:text> <xsl:value-of select="$newline"/> <xsl:text> normalize-space($newline)="</xsl:text> <xsl:value-of select="normalize-space($newline)"/> <xsl:text>"</xsl:text> <xsl:value-of select="$newline"/> <xsl:text> normalize-space($testString)="</xsl:text> <xsl:value-of select="normalize-space($testString)"/> <xsl:text>"</xsl:text> <xsl:value-of select="$newline"/> </xsl:template> </xsl:stylesheet> Das Stylesheet erzeugt die folgende Ausgabe: Tests of the normalize-space() function: normalize-space(' Hello, World!')="Hello, World!" normalize-space($newline)=" normalize-space($testString)="This is a string with lots of whitespace." |