xml – 如何使用XSLT转换NEWLINE?

Possible Duplicate:
07000

如何将NEWLINE转换为< BR />用XSLT?

我有

<text>
some text with 
new lines
</text>

我希望有

<p> some text with <br /> new lines </p>
这种转变:
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="t">
  <p>
    <xsl:apply-templates/>
  </p>
 </xsl:template>

 <xsl:template match="text()" name="insertBreaks">
   <xsl:param name="pText" select="."/>

   <xsl:choose>
     <xsl:when test="not(contains($pText,'&#xA;'))">
       <xsl:copy-of select="$pText"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of select="substring-before($pText,'&#xA;')"/>
       <br />
       <xsl:call-template name="insertBreaks">
         <xsl:with-param name="pText" select=
           "substring-after($pText,'&#xA;')"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

当应用于此XML文档时:

<t>Line1
Line2
Line3
</t>

产生想要的,正确的结果:

<p>Line1<br />Line2<br />Line3<br /></p>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念