需要为特定实例提供符号

时间:2017-01-31 07:24:04

标签: xml xslt

我需要在多个para的条件之间添加'+'符号,如果单个para条件需要忽略符号

我的输入XML文件是:

<text>
 <top>
 <p>This thesis statement is not your main point; it is the main point of your source.</p>
 </top>
 <bottom>
 <p>Combine sentences in Step Two to form your summary; organize your summary sentences.</p>
 <p>Summaries differ from more closely follow the original text's presentation.</p>
 </bottom>
</text>

XSL我用作:

<xsl:stylesheet version="3.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:json="http://json.org/" xmlns:mf="http://example.com/mf"
 exclude-result-prefixes="#all">

 <xsl:template match="text">
  text: {
  <xsl:apply-templates/>
  },
 </xsl:template>

<xsl:template match="top">
  "top": <xsl:apply-templates/>,
 </xsl:template>

 <xsl:template match="bottom">
  "bottom": <xsl:apply-templates/>,
 </xsl:template>

 <xsl:template match="p">
  <xsl:variable name="span">
   <span>
    <xsl:apply-templates/>
   </span>
  </xsl:variable>
  <xsl:text>&#10;</xsl:text>
  <xsl:sequence select="mf:break(normalize-space(serialize($span, $ser-params)))"/>
  <xsl:if test="position() != 2">+</xsl:if>
 </xsl:template>

 </xsl:stylesheet>

输出我得到了:

text: {

"top": 
"<span>This thesis statement is not your main point; it is the main" +
"point of your source.</span>"+,

"bottom": 
"<span>Combine sentences in Step Two to form your summary; organize" +
 "your summary sentences.</span>"+
"<span>Summaries differ from more closely follow the original text's" +
 "presentation.</span>",

},

预期输出为:

text: {

"top": 
"<span>This thesis statement is not your main point; it is the main" +
"point of your source.</span>",

"bottom": 
"<span>Combine sentences in Step Two to form your summary; organize" +
 "your summary sentences.</span>"+
"<span>Summaries differ from more closely follow the original text's" +
 "presentation.</span>",

},

+符号需要介于para之间。我使用Saxon-PE 9.6.0.7。请分享一些关于此的想法。提前致谢

1 个答案:

答案 0 :(得分:0)

检查最后一个@PUT @Path("/{accountID}") @Consumes("application/json") @Produces("application/json") public final Response testPut(String jsonString) { ... 元素:

<p>