как заголовок xsl - PullRequest
       3

как заголовок xsl

0 голосов
/ 03 сентября 2011

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...
</data>

Мне нужно добавить абзац для каждого предложения после ... в xsl, а абзац должен содержать более 1 строки.

XML

             I need to write XSL for the above xml to get the out like this.

Производство самого опия практически не изменилось с древних времен. Торговля опиумом стала более регулярной к семнадцатому веку, когда он был смешан с табаком для курения, и впервые была выявлена ​​зависимость. Это тестовое сообщение 3.

              <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.</p>

1 Ответ

1 голос
/ 03 сентября 2011

Это то, что вы ищете?Он использует рекурсивный шаблон для поиска периодов в тексте.Он помещает текст до первого периода в теге абзаца HTML, а затем рекурсивно вызывает шаблон для текста после периода.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="html"/>
   <xsl:template match="/data">
      <xsl:call-template name="paragraph">
         <xsl:with-param name="text" select="text()"/>
         <xsl:with-param name="separator" select="'...'"/>
         <xsl:with-param name="replace" select="'.'"/>
      </xsl:call-template>
   </xsl:template>
   <xsl:template name="paragraph">
      <xsl:param name="text"/>
      <xsl:param name="separator"/>
      <xsl:param name="replace"/>
      <xsl:choose>
         <xsl:when test="contains($text,$separator)">
            <xsl:variable name="firsttext" select="normalize-space(substring-before($text,$separator))"/>
            <xsl:if test="string-length($firsttext) &gt; 0">
               <p>
                  <xsl:value-of select="$firsttext"/>
                  <xsl:value-of select="$replace"/>
               </p>
            </xsl:if>
            <xsl:call-template name="paragraph">
               <xsl:with-param name="text" select="normalize-space(substring-after($text,$separator))"/>
               <xsl:with-param name="separator" select="$separator"/>
               <xsl:with-param name="replace" select="$replace"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="string-length($text) &gt; 0">
            <xsl:value-of select="normalize-space($text)"/>
            <xsl:value-of select="$replace"/>
         </xsl:when>
      </xsl:choose>
   </xsl:template>
</xsl:stylesheet>

Это приводит к следующему выводу:

<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&amp;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.</p>

Обратите внимание, что ваш текущий входной XML недопустим из-за присутствия & в.Я предполагал, что вы хотите сделать &

Если вы искали только текстовый вывод, а не теги абзаца HTML, вы можете заменить создание элементов p в первом xsl: когда с этим кодом.

   <xsl:value-of select="$firsttext" />
   <xsl:value-of select="$replace"/>
   <xsl:text>&#13;</xsl:text>
   <xsl:text>&#13;</xsl:text>

Когда вы сделаете это, вывод будет следующим:

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&amp;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.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...