Ecco un approccio che utilizza un modello ricorsivo, che cerca
nella stringa dal database e quindi emette il sottostringa prima. Se c'è una sottostringa dopo il
rimanente, il modello chiama se stesso fino a quando non rimane nulla. Nel caso
non è presente, il testo viene semplicemente emesso.
Ecco la chiamata modello (basta sostituire @ActivityExtDescription con il campo del database):
<xsl:call-template name="MultilineTextOutput">
<xsl:with-param name="text" select="@ActivityExtDescription" />
</xsl:call-template>
e qui è il codice per il modello stesso:
<xsl:template name="MultilineTextOutput">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, ' ')">
<xsl:variable name="text-before-first-break">
<xsl:value-of select="substring-before($text, ' ')" />
</xsl:variable>
<xsl:variable name="text-after-first-break">
<xsl:value-of select="substring-after($text, ' ')" />
</xsl:variable>
<xsl:if test="not($text-before-first-break = '')">
<xsl:value-of select="$text-before-first-break" /><br />
</xsl:if>
<xsl:if test="not($text-after-first-break = '')">
<xsl:call-template name="MultilineTextOutput">
<xsl:with-param name="text" select="$text-after-first-break" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" /><br />
</xsl:otherwise>
</xsl:choose>
Opere come un fascino !!!
fonte
2013-07-26 16:38:18
Vedere questa domanda molto simile: http://stackoverflow.com/questions/723226/producing-a-new-line-in-xslt – Coder