问题
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, '
'))">
<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>
回答1:
To set a newline you can use:
<xsl:text>
</xsl:text>
来源:https://stackoverflow.com/questions/18051289/how-to-set-newline-and-tab-in-paragraph-using-xslt