如何使用xsl创建一个多行的段落

时间:2011-09-13 18:00:27

标签: xslt

在一个段落中我应该有多行,它应该像3行或更多,但不只是一个喜欢和另一个东西是我需要删除'...','...'并替换它只是周期。

我需要在xsl中为...之后的每个句子添加句点,并且段落需要超过1行。

我需要用每个句子中的句号替换...并且段落需要超过1行。使用xsl

XML看起来像这样:

<data>The production of opium itself has basically not changed since
ancient times...Opium trade became more regular by the seventeenth
century, when it was mixed with tobacco for smoking, and addiction was
first recognized... This is a test Message3…This is showing off a
handful of updates to its line of audio accessories this week at IFA
in Berlin. At top of the list is the newly revealed inAir 5000, a
hefty tabletop AirPlay speaker that the company is firmly positioning
to take on Bowers&Wilkins' Zeppelin line (which also recently got its
own AirPlay version)... Like that system, the inAir certainly offers a
unique take on aesthetics, with a teardrop design. The company opted
not to install an Apple dock on the 110 watt system, given that
compatible devices can stream audio wirelessly to the thing via
AirPlay...Twice a month, tourists board a bus and embark on a "fact-finding mission" to one of the hottest spots in the immigration debate -- the Arizona-Mexico border. Tourists are encouraged to make make up their own minds. </data>

我的输出应该如下所示:段落需要分成三个相等的线。

<p>This is showing off a handful of updates to its line of audio accessories this week at IFA in Berlin. At top of the list is the newly revealed inAir 5000, a hefty tabletop AirPlay speaker that the company is firmly positioning to take on Bowers&Wilkins' Zeppelin line (which also recently got its own AirPlay version).</p>
              <p>Like that system, the inAir certainly offers a unique take on aesthetics, with a teardrop design. The company opted not to install an Apple dock on the 110 watt system, given that compatible devices can stream audio wirelessly to the thing via AirPlay.Twice a month, tourists board a bus and embark on a "fact-finding mission" to one of the hottest spots in the immigration debate -- the Arizona-Mexico border. Tourists are encouraged to make make up their own minds.</p>

请帮帮我。

1 个答案:

答案 0 :(得分:1)

您可以使用这样的递归模板:

<xsl:template match="data" name="data">
  <xsl:param name="text" select="." />
  <xsl:choose>
    <xsl:when test="contains($text,'...')">
      <xsl:call-template name="data">
        <xsl:with-param name="text" select="substring-before($text,'...')" />
      </xsl:call-template>
      <xsl:call-template name="data">
        <xsl:with-param name="text" select="substring-after($text,'...')" />
      </xsl:call-template>
    </xsl:when>

    <xsl:when test="contains($text,'…')">
      <xsl:call-template name="data">
        <xsl:with-param name="text" select="substring-before($text,'…')" />
      </xsl:call-template>
      <xsl:call-template name="data">
        <xsl:with-param name="text" select="substring-after($text,'…')" />
      </xsl:call-template>
    </xsl:when>

    <xsl:otherwise>
      <p>
        <xsl:value-of select="concat($text,'.')" />
      </p>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

这基本上做的是每当它处理任何带有......或......的文本时,它就会在...... / ...之前和之后调用自己,以相同的方式处理每个部分。如果它中没有,它只输出一个段落和一个句号。

给出样本,这实际上会在底部给你一个空段,因为它以...结尾;你可以用<xsl:otherwise>替换最后<xsl:when test="normalize-space($text)">(以及相应的结束标记)来删除这样的空段落。