开发者

How to make a paragraph more than one line using xsl

In a paragraph i should have more than one line it should be like 3 line or more,but not just one like and one another thing is i need to remove '...', '…' and replace it with just period.

I need to added period for each sentence after ... in xsl, and paragraph needs to be more than 1 line.

I need to replace ... with period in each sentence and paragraph needs to be more than 1 line. using xsl

XML looks like this:

<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>

My out put should look like this: Paragraph needs to split into three equal lines.

<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 s开发者_运维知识库peaker 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>

Please help me out.


You can use a recursive template like this:

<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>

What this basically does is whenever it processes any text that has a ... or … in it, it calls itself with whatever's before and after the .../…, processing each piece in the same way. If it doesn't have either in it, it just outputs a paragraph, and a full stop.

With the sample given, this will actually give you an empty paragraph at the bottom, because it ends with ...; you can strip out empty paragraphs like this by replacing the last <xsl:otherwise> with <xsl:when test="normalize-space($text)"> (And the corresponding closing tag).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜