【问题标题】:First section title font size needs to be increase by using xslt第一部分标题字体大小需要使用 xslt 增加
【发布时间】:2016-09-12 11:21:16
【问题描述】:

在我的 xml 中有三个部分标题,都在 h1 位置,但我希望第一部分作为 h1 位置,remaning 必须是 h2 位置,我的 xml 文件是

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

我使用 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>

请指导我。谢谢

【问题讨论】:

  • 我不完全理解您所说的“但我希望第一部分本身的字体比其他部分标题的字体高”以及问题出在哪里。您的代码 contains(@class,' topic/section ') 没有意义,您的 xml 中没有 @class 属性,如果有,为什么它应该包含 space 主题/部分 space?跨度>
  • contains(@class,' topic/section ') 表示@BoopathyChandran 使用 DITA,他正在开发 PDF 插件样式表。
  • 绝对是的。你明白了 tmakita。你对此有任何想法
  • DITA 1.8.5 版本

标签: xml pdf xslt xsl-fo


【解决方案1】:

这是我可以发送的最小模板。

  • 我发现您的第一个模板与任何 section 元素都不匹配,因为您输入的所有 XML 文件部分元素都有标题元素。
  • 相反,我为 H1 和 H2 添加了两个 xsl:attribute-set,并根据部分元素位置应用它们。

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

可能你想做更复杂的转换,但我希望这个例子对你的开发有所帮助。

【讨论】:

    【解决方案2】:

    你可以使用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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-10
      • 2016-12-01
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      相关资源
      最近更新 更多