如何使用 xslt 在段落中设置换行符和制表符 [英] how to set newline and tab in paragraph using xslt

查看:70
本文介绍了如何使用 xslt 在段落中设置换行符和制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to set newline and tab in paragraph using XSLT values from xml retrieve using XML Parsing.Following XSLT code separates each word in paragraph.But,I want to separate newline in paragraph wherever necessary and also I want to set tab before starting a paragraph...

    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>

推荐答案

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

To set a newline you can use:

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

这篇关于如何使用 xslt 在段落中设置换行符和制表符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆