2009-12-17 45 views

回答

1
 <!-- Get text. Replace all 「break with 「 --> 
     <xsl:variable name="linebreak"> 
      <xsl:text> 
</xsl:text> 
     </xsl:variable> 
     <xsl:variable name="text"> 
      <xsl:call-template name="replace-string"> 
       <xsl:with-param name="text" select="."/> 
       <xsl:with-param name="replace" select="concat('「',$linebreak)" /> 
       <xsl:with-param name="with" select="string('「')"/> 
      </xsl:call-template> 
     </xsl:variable> 


     <xsl:value-of select="$text"/> 
+7

而且將在什麼地方'取代,string'模板是什麼? – 2009-12-18 07:25:47

11

如果您使用的變換生成HTML輸出,最簡單的方法通常是:

<xsl:value-of select="normalize-space($text)"/> 

normalize-space帶開頭和結尾的空白,並用字符串中替換的多個空格字符運行單一空間。

要準確地刪除尾隨CR/LF對:

<xsl:choose> 
    <xsl:when test="substring(., string-length(.)-1, 2) = '&#xD;&#xA;'"> 
     <xsl:value-of select="substring(., 1, string-length(.)-2)"/> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="."/> 
    </xsl:otherwise> 
</xsl:choose> 
+4

+1爲「正常化空間」 - 爲我節省了一大筆痛苦 – 2012-04-24 14:39:35