如何使用XSLT在xml中设置换行符 [英] How to set newline in xml using XSLT

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

问题描述

这是基于空间的换行编码,但我需要换行的地方......



xml:



 <   item  >  
< id > 1 < / id >
< title > 恢复< / title >
< desc > 您的目标,教育资格,经验,相关技能的摘要你要进入的工作领域。在这里你可以详细介绍每一项。它突出了你的成就,向潜在的雇主证明你有资格胜任你想要的工作。记住它不是你所做的一切的传记。它的核心目的是让你接受采访。< / desc >
< / item >







XSLT:

< pre lang =xml> < xsl:stylesheet 版本 = 1.0

xmlns:xsl = http://www.w3.org/1999/XSL/转换 >
< xsl:output omit-xml-declaration = 缩进 = / >

< xsl:template 匹配 = t >
< p >
< xsl:apply-templates / >
< / p >
< / xsl:template >

< xsl:template 匹配 = text() name = insertBreaks >
< xsl:param name = pText 选择 = / >

< xsl:choose >
< xsl:当 test = not(包含($ pText,'& #xA;')) >
< xsl:copy-of 选择 = $ pText / >
< / xsl:when >
< ; xsl:否则 >
< xsl:value-of 选择 = substring-before($ pText,'& #xA;') / >
< br / >

< xsl:call-template 名称 = < span class =code-keyword> insertBreaks >
< xsl:with-param name < span class =code-keyword> = pText 选择 =
substring-after($ pText,'& #xA;') / >
< / xsl:call-template >
< / xsl:otherwise < span class =code-keyword>>
< / xsl:choose >
< / xsl:template >
< / xsl:stylesheet >

解决方案

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 名称 = pText 选择 =
substring-后(

Here is a coding for newline based on space but i need wherever newline is necessary...

xml:

<item>
    <id>1</id>
    <title>Resume</title>
    <desc>A summary of your objectives,educational qualification,experience,skills relevant to the field of work you are going to enter.Here you can detail down each.It highlights your accomplishments to show a potential employer that you are qualified for the work you want.Remember it is not a biography of everything you have done.Its core PURPOSE is to get you an interview.</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>

解决方案

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(


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

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