normalize-space() 関数  
パラメータ文字列から余分な空白スペースを削除します。
 
入力

省略可能な文字列。パラメータを省略すると、normalize-space() 関数はコンテキストノードの文字列値を使用します。

 
出力

次のように空白スペースを削除したパラメータ文字列。

    先頭のすべての空白スペースが削除されます。

    末尾のすべての空白スペースが削除されます。

    文字列内で空白スペースが連続している場合は、1 つの空白スペースに置き換えられます。

 
定義先

XPath 4.2 節「文字列関数」

 

normalize-space() の動作を示す短い例を次に示します。

<?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>

このスタイルシートからは、次のような出力が生成されます。


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."