xml – 如何使用XSLT转换NEWLINE?
发布时间:2020-12-16 08:03:32 所属栏目:百科 来源:网络整理
导读:Possible Duplicate: 07000 如何将NEWLINE转换为 BR /用XSLT? 我有 textsome 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:outp
如何将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,'
'))"> <xsl:copy-of select="$pText"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring-before($pText,'
')"/> <br /> <xsl:call-template name="insertBreaks"> <xsl:with-param name="pText" select= "substring-after($pText,'
')"/> </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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |