2016-09-12 1 views
0

В моем xml, имеющем три раздела, все находятся в позиции h1, но я хочу, чтобы первый раздел был как позиция h1, а remaning должен быть h2-позициями, а мой xml-файлРазмер шрифта заголовка первого раздела нужно увеличить с помощью xslt

<section> 
     <title>DESCRIPTION</title> 
     <p>The A380 is available with two types of turbofan engines, the 
Rolls-Royce Trent 900 (variants A380-841, −842 and −843F) or the Engine 
Alliance GP7000 (A380-861 and −863F). Noise reduction was an important 
requirement in the A380 design, and particularly affects engine design.</p> 
     <p>Landing gears<ul> 
       <li> 
        <p>Nose Landing Gear</p> 
       </li> 
       <li> 
        <p>Wing Landing Gear (Bogie Type, 4 Wheels - 4 Braked)</p> 
       </li> 
       <li> 
        <p>Body Landing Gear (Bogie Type, 6 Wheels - 4 Braked)</p> 
       </li> 
      </ul> 
     </p> 
     </section> 
     <section> 
     <title>Wing Landing Gear</title> 
     <p>Each wing landing gear has a leg assembly and 
a four-wheel bogie beam. The WLG leg includes a Bogie Trim Actuator 
(BTA) and an oleo-pneumatic shock absorber.</p> 
     </section> 
     <section> 
     <title>Body Landing Gear</title> 
     <p>The two body landing gears have a six-wheel bogie 
beam and a leg assembly that includes an oleo- pneumatic shock absorber. 
A two-piece drag-stay assembly mechanically locks the leg in the extended 
position.</p> 
     <fig> 
      <title>Landing gear</title> 
      <image align="center" href="../ICN-HSXWB-A-791111-H-F0302-00001-A-001-01.tif"/> 
     </fig> 
     </section> 

Im используя XSLT в качестве

<xsl:template match="*[contains(@class,' topic/section ')][@spectitle != '' 
         and not(*[contains(@class, ' topic/title ')])]" 
    mode="dita2xslfo:section-heading" 
    priority="10"> 
    <fo:block xsl:use-attribute-sets="section.title"> 
     <xsl:call-template name="commonattributes"/> 
     <xsl:variable name="spectitleValue" as="xs:string" select="string(@spectitle)"/> 
     <xsl:variable name="resolvedVariable"> 
     <xsl:call-template name="insertVariable"> 
      <xsl:with-param name="theVariableID" select="$spectitleValue"/> 
     </xsl:call-template> 
     </xsl:variable> 
     <xsl:sequence 
     select="if (not(normalize-space($resolvedVariable))) 
     then $spectitleValue 
     else $resolvedVariable" 
     /> 
    </fo:block> 

<xsl:template match="*[contains(@class,' topic/section ')]"> 
     <fo:block xsl:use-attribute-sets="section"> 
      <xsl:call-template name="commonattributes"/> 
      <xsl:apply-templates select="." mode="dita2xslfo:section-heading"/> 
      <xsl:apply-templates/> 
     </fo:block> 
    </xsl:template> 

Пожалуйста, руководство меня об этом. Спасибо

+0

Я не совсем понимаю, что вы имеете в виду под «Но я хочу, чтобы первый раздел сам шрифт на высоком уровне, чем другой заголовок раздела» и где проблема кроется. Ваш код 'содержит (@class, 'topic/section')' не имеет смысла, в вашем xml-атрибуте нет атрибута @class, а если есть, то почему он должен содержать ** пробел ** тема/раздел ** пробел * *? –

+0

Пожалуйста, напишите [Минимальный, полный и проверенный пример] (https://stackoverflow.com/help/mcve) –

+1

'содержит (@class, 'topic/section')' означает, что @BoopathyChandran использует DITA, и он разрабатывает таблицу стилей PDF-плагина. – tmakita

ответ

0

Это минимальный шаблон, который я могу отправить.

  • Я нашел, что ваш первый шаблон не соответствует ни одному элементу section, потому что все элементы вашего входного файла XML-файла имеют элемент заголовка.
  • Вместо этого я добавил два набора атрибутов xsl: для H1 и H2 и применил их положение элемента секции.

    <xsl:attribute-set name="section.title.h1" use-attribute-sets="section.title"> 
        <xsl:attribute name="font-size">20pt</xsl:attribute> 
    </xsl:attribute-set> 
    
    <xsl:attribute-set name="section.title.h2" use-attribute-sets="section.title"> 
        <xsl:attribute name="font-size">12pt</xsl:attribute> 
    </xsl:attribute-set> 
    
    <xsl:template match="*[contains(@class, ' topic/section ')]"> 
        <fo:block xsl:use-attribute-sets="section"> 
         <xsl:call-template name="commonattributes"/> 
         <!--xsl:apply-templates select="." mode="dita2xslfo:section-heading"/--> 
         <xsl:apply-templates/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="*[contains(@class, ' topic/section ')]/*[contains(@class, ' topic/title ')]"> 
        <xsl:choose> 
         <xsl:when test="empty(parent::*/preceding-sibling::*[contains(@class, ' topic/section ')])"> 
          <fo:block xsl:use-attribute-sets="section.title.h1"> 
           <xsl:call-template name="commonattributes"/> 
           <xsl:apply-templates/> 
          </fo:block> 
         </xsl:when> 
         <xsl:otherwise> 
          <fo:block xsl:use-attribute-sets="section.title.h2"> 
           <xsl:call-template name="commonattributes"/> 
           <xsl:apply-templates/> 
          </fo:block> 
         </xsl:otherwise> 
        </xsl:choose> 
    </xsl:template> 
    

Возможно, вы хотите сделать более сложные преобразования, но я надеюсь, что этот пример поможет вашему развитию.

0

Вы можете использовать функцию position() для достижения этой цели:

<xsl:choose> 
    <xsl:when test="position() = 1"> 
      <!--attributes for H1 go here--> 
     <xsl:attribute name="font-size">24</xsl:attribute> 
    </xsl:when> 
    <xsl:otherwise> 
     <!--attributes for H2 go here--> 
     <xsl:attribute name="font-size">18</xsl:attribute> 
    </xsl:otherwise> 
</xsl:choose> 
+0

спасибо. Его рабочий штраф –