如何使用xslt在段落中设置换行符和制表符

时间:2013-08-05 05:44:22

标签: xslt xml-parsing

我想使用XML解析使用来自xml检索的XSLT值在段落中设置换行符和制表符。以下XSLT代码分隔段落中的每个单词。但是,我想在必要时将段中的换行符分开,并且我想在之前设置制表符开始一段...

    sample.xml
      <item>
      <id>0</id>
      <desc>Review your resume, and make sure that you can explain everything on it. Arrive at the interview ten minutes early to give yourself an opportunity to collect your thoughts and relax. Be aware that many employers will have their receptionist’s record the time you came in. If you rush in at the last minute, an employer may have serious concerns about your ability to arrive on time for a normal day at work.</desc>
      </item>

    xslt:

     <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>

1 个答案:

答案 0 :(得分:1)

要设置换行,您可以使用:

<xsl:text>&#xa;</xsl:text>