1. 首先將xml文件中的內(nèi)容用CDATA顯示,即:
<content>
<![CDATA[
這里有個(gè)回車(chē)<br />挖哈哈
]]>
</content>
然后在xsl中如下調(diào)用:
<xsl:value-of select="content" disable-output-escaping="yes" />
即可
此法可以顯示所有的html代碼,實(shí)現(xiàn)也較為簡(jiǎn)單
2. 如果是希望xsl顯示一段含有 的文字,并將中間的換行顯示出來(lái),則可以考慮下面的方法(此方法不能轉(zhuǎn)換html代碼)
使用xsl寫(xiě)的一個(gè)方法
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:template name="br">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,' ')">
<xsl:value-of select="substring-before($string,' ')"/><br/>
<xsl:call-template name="br">
<xsl:with-param name="string" select="substring-after($string,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
存為brfunc.xsl
然后在xsl文件頭導(dǎo)入此文件(必須緊接<xsl:stylesheet...>之下)
<xsl:import href="brfunc.xsl" />
在文件中需要調(diào)用時(shí),方法
<xsl:call-template name="br">
<xsl:with-param name="string" select="content" />
</xsl:template>
此方法較為繁瑣,如果只需要轉(zhuǎn)換換行符的話可以考慮
3. 基本和上面的功能差不多,但比上面一種簡(jiǎn)單得多,呵呵~~
在xsl里面:
聯(lián)系客服