2016-07-04 11 views
0

XSLTの結果で、複数の改行文字を1つの改行文字に置き換えることを検討しています。 xmlノード内XSLT - 複数の改行を1つの改行に置き換えます。

私が持っている可能性があり、以下:

<description> 
    A description that goes over multiple lines, because: 

     - someone inputted the data in another system 
     - and there are gaps between lines 

    Another gap above this 
</description> 

私はそう表示されるように、このノードのうちテキストが欲しい:

A description that goes over multiple lines, because: 
    - someone inputted the data in another system 
    - and there are gaps between lines 
Another gap above this 

これを実行する方法はありますXSLTを使用していますか? XSLT 1.0(libxsltの)を使用して

+0

あなたがXSLT 1.0または2.0を使用していますか? –

+0

私はlibxml 1.1.28を使用しています。これはXSLT 1.0(http://xmlsoft.org/XSLT/)を使用しています。 –

答えて

2

方法について:

<xsl:template match="description"> 
    <xsl:call-template name="normalize-returns"> 
     <xsl:with-param name="text" select="."/> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="normalize-returns"> 
    <xsl:param name="text"/> 
    <xsl:choose> 
     <xsl:when test="contains($text, '&#10;&#10;')"> 
      <!-- recursive call --> 
      <xsl:call-template name="normalize-returns"> 
       <xsl:with-param name="text"> 
        <xsl:value-of select="substring-before($text, '&#10;&#10;')"/> 
        <xsl:text>&#10;</xsl:text> 
        <xsl:value-of select="substring-after($text, '&#10;&#10;')"/> 
       </xsl:with-param> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="$text"/> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
+0

これは素晴らしいことです!私は自分のコードに合わせていくつかの変更を加えなければならなかったが、本質的にうまくいった。 –

関連する問題