Section Element需要在另一个section元素之前关闭(docbook to dita)

时间:2016-10-11 06:32:49

标签: xml xslt dtd docbook dita

我的输入文件是docbook.xml,我的输出需要在DITA中使用Topic DTD。在Topic DTD中,第2级部分元素不允许在第1级部分元素内部。 这是我的输入xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book
  PUBLIC "-//OASIS//DTD DocBook V5.0//EN" "http://docbook.org/xml/5.0/dtd/docbook.dtd">
<book xmlns="http://docbook.org/ns/docbook"><article><info><bibliomisc role="data.module.code">HSXWB-A-79-11-11-00A01-000A-D</bibliomisc><issuenum>001</issuenum><date>2016-01-29</date><title>LANDING GEAR</title><subtitle>FUNCTION, DATA
FOR PLANS AND DESCRIPTION</subtitle><bibliomisc role="classification">01</bibliomisc><bibliomisc role="responsible.partner.company">F0302</bibliomisc><bibliomisc role="originator">F0302</bibliomisc><bibliomisc role="applicability">ALL</bibliomisc><bibliomisc role="data.module.reference.code">TRENTXWB-A-00-00-00-01A01-022A-D</bibliomisc><bibliomisc role="quality.assurance">tabtop</bibliomisc><bibliomisc role="skill.level">sk01</bibliomisc><bibliomisc role="reason.for.update">First Release</bibliomisc><bibliomisc role="publication.code">UNKNOWN PUBLICATION</bibliomisc></info><?dbfo-need height="2cm"?><section><title>DESCRIPTION</title>
<para>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.</para>
<para>Landing gears<itemizedlist>
<listitem><para>Nose Landing Gear</para>
</listitem>
<listitem><para>Wing Landing Gear (Bogie Type, 4 Wheels  - 4 Braked)</para>
</listitem>
<listitem><para>Body Landing Gear (Bogie Type, 6 Wheels  - 4 Braked)</para>
</listitem>
</itemizedlist></para>
<section><title>Wing Landing Gear</title>
<section><para>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.</para>
</section></section><section><title>Body Landing Gear</title>
<section><para>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.</para>
</section></section></section>
<section><figure xml:id="HSXWB-A-79-11-11-00A01-000A-DTRENTXWB-A-00-00-00-01A01-022A-D-fig-0001" label="1"><title>Landing gear</title>
<mediaobject><imageobject><imagedata align="center" fileref="ICN-HSXWB-A-791111-H-F0302-00001-A-001-01.tif"/></imageobject></mediaobject>
</figure></section>
</article></book>

实际输出我得到:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE topic
  PUBLIC "com.rsicms.rsuite_te:doctypes:dita:topic" "topic.dtd">
<topic id="topic_1">
   <title outputclass="title">LANDING GEARLANDING GEAR</title>
   <titlealts>
      <navtitle>FUNCTION, DATA
FOR PLANS AND DESCRIPTION</navtitle>
   </titlealts>
   <prolog>
      <metadata>
         <data-about>
            <data type="data.module.code">HSXWB-A-79-11-11-00A01-000A-D</data>
            <data type="classification">01</data>
            <data type="responsible.partner.company">F0302</data>
            <data type="originator">F0302</data>
            <data type="applicability">ALL</data>
            <data type="data.module.reference.code">TRENTXWB-A-00-00-00-01A01-022A-D</data>
            <data type="quality.assurance">tabtop</data>
            <data type="skill.level">sk01</data>
            <data type="reason.for.update">First Release</data>
            <data type="publication.code">UNKNOWN PUBLICATION</data>
         </data-about>
         <foreign outputclass="issuenum">001</foreign>
         <unknown outputclass="date">2016-01-29</unknown>
      </metadata>
   </prolog>
   <body>
      <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>
            <title>Wing Landing Gear</title>
            <section>
               <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>
         <section>
            <title>Body Landing Gear</title>
            <section>
               <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>
            </section>
         </section>
      </section>
      <section>
         <title>Landing gear</title>
         <image align="center" href="ICN-HSXWB-A-791111-H-F0302-00001-A-001-01.tif"/>
      </section>
   </body>
</topic>

我的xsl文件:

<xsl:template match="*|text()|@*">
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>

<xsl:template match="section">
        <section>       
            <xsl:apply-templates/>
        </section>      
    </xsl:template>

<xsl:template match="title">
        <title>       
            <xsl:apply-templates/>
        </title>      
    </xsl:template>

<xsl:template match="itemizedlist">
        <ul>       
            <xsl:apply-templates/>
        </ul>      
    </xsl:template>

<xsl:template match="listitem">
        <li>
            <xsl:apply-templates/>
        </li>
    </xsl:template>

    <xsl:template match="para">
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="figure">
        <xsl:apply-templates/>
     </xsl:template>

    <xsl:template match="imagedata">
        <image>
            <xsl:apply-templates select="@*"/>
        </image>
    </xsl:template>

<xsl:template match="@fileref">
   <xsl:attribute name="href">
      <xsl:value-of select="."/>
   </xsl:attribute>
</xsl:template>

    <xsl:template match="mediaobject">

            <xsl:apply-templates/>

    </xsl:template>

    <xsl:template match="imageobject">

            <xsl:apply-templates/>

    </xsl:template>

Excepted Output xml as:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE topic
  PUBLIC "com.rsicms.rsuite_te:doctypes:dita:topic" "topic.dtd">
<topic id="topic_1">
   <title outputclass="title">LANDING GEARLANDING GEAR</title>
   <titlealts>
      <navtitle>FUNCTION, DATA
FOR PLANS AND DESCRIPTION</navtitle>
   </titlealts>
   <prolog>
      <metadata>
         <data-about>
            <data type="data.module.code">HSXWB-A-79-11-11-00A01-000A-D</data>
            <data type="classification">01</data>
            <data type="responsible.partner.company">F0302</data>
            <data type="originator">F0302</data>
            <data type="applicability">ALL</data>
            <data type="data.module.reference.code">TRENTXWB-A-00-00-00-01A01-022A-D</data>
            <data type="quality.assurance">tabtop</data>
            <data type="skill.level">sk01</data>
            <data type="reason.for.update">First Release</data>
            <data type="publication.code">UNKNOWN PUBLICATION</data>
         </data-about>
         <foreign outputclass="issuenum">001</foreign>
         <unknown outputclass="date">2016-01-29</unknown>
      </metadata>
   </prolog>
   <body>
      <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>

         </section>

      <section>
         <title>Landing gear</title>
         <image align="center" href="ICN-HSXWB-A-791111-H-F0302-00001-A-001-01.tif"/>
      </section>
   </body>
</topic>

请就此向我提出建议。提前致谢

1 个答案:

答案 0 :(得分:0)

在您的具体示例中,您可以尝试将以下模板集成到XSLT中:

<xsl:template match="section">
    <section>
        <xsl:apply-templates select="node()[not(self::section)]"/>
    </section>
    <xsl:apply-templates select="section"/>
</xsl:template>