0

具有不同输出类的 Paras 作为主要和子级别的标题部分

我的输入 xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "urn:pubid:doctypes:dita:topic" "topic.dtd">
<topic id="topic_1" xml:lang="en-US" outputclass="Sec-Chapter">
  <title>Sec-Chapter</title>
  <body>
    <p outputclass="Title">Heading Mappings</p>
    <p outputclass="A-Head">A-Head</p>
    <p>Some paragraph text</p>
    <p outputclass="B-Head">B-Head</p>
    <p>Some more paragraph text</p>
    <p outputclass="C-Head">C-Head</p>
    <p>Yet more paragraph text</p>
    <p outputclass="D-Head">D-Head</p>
    <p>Some creative paragraph text</p>
    <p outputclass="E-Head">E-Head</p>
    <p>Now, boing paragraph text</p>
    <p outputclass="F-Head">F-Head</p>
    <p>Finally, end</p>
  </body>
</topic>

我用于创建标题级别的 XSL 模板:

    <xsl:template match="//body">
    <xsl:copy>
      <xsl:for-each-group select="*" group-starting-with="//p[@outputclass = 'A-head']">
        <h2><xsl:value-of select="//p[@outputclass = 'A-head']"/></h2>
        <section>
<xsl:apply-templates select="."/>
          <xsl:for-each-group select="current-group() except ." group-starting-with="//p[@outputclass = 'B-head']">
            <h3><xsl:value-of select="//p[@outputclass = 'B-head']"/></h3>
            <section>
<xsl:apply-templates select="."/>
              <xsl:for-each-group select="current-group() except ." group-starting-with="//p[@outputclass = 'C-head']">
                <h4><xsl:value-of select="//p[@outputclass = 'C-head']"/></h4>
                <section>
<xsl:apply-templates select="."/>
                  <xsl:for-each-group select="current-group() except ." group-starting-with="//p[@outputclass = 'D-head']">
                    <h5><xsl:value-of select="//p[@outputclass = 'D-head']"/></h5>
                    <section>
<xsl:apply-templates select="."/>
                      <xsl:for-each-group select="current-group() except ." group-starting-with="//p[@outputclass = 'E-head']">
                        <h6><xsl:value-of select="//p[@outputclass = 'E-head']"/></h6>
                        <section>
<xsl:apply-templates select="."/>
                          <xsl:for-each-group select="current-group() except ." group-starting-with="//p[@outputclass = 'F-head']">
                            <h6><xsl:value-of select="//p[@outputclass = 'F-head']"/></h6>
                            <section>
                              <xsl:apply-templates select="."/>
                            </section>
                          </xsl:for-each-group>
                        </section>
                      </xsl:for-each-group>
                    </section>
                  </xsl:for-each-group>
                </section>
              </xsl:for-each-group>
            </section>
          </xsl:for-each-group>
        </section>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

我使用上面的模板得到输出:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en-us" lang="en">
    <head>
        <title>Heading</title>
    </head>
    <body>
        <h2>A-Head</h2>
        <section></section>
        <h2>A-Head</h2>
        <section>
           <h3>B-Head</h3>
           <section></section>
           <h3>B-Head</h3>
           <section>
              <h4>C-Head</h4>
              <section></section>
              <h4>C-Head</h4>
              <section>
                 <h5>D-Head</h5>
                 <section></section>
                 <h5>D-Head</h5>
                 <section>
                    <h6>E-Head</h6>
                    <section></section>
                    <h6>E-Head</h6>
                    <section>
                       <h6>F-Head</h6>
                       <section>
                          <p class="p">Now, boing paragraph text</p>

                       </section>
                       <h6>F-Head</h6>
                       <section>
                          <h6>F-Head</h6>

                       </section>
                    </section>
                 </section>
              </section>
           </section>
        </section>
     </body>
</html>

但我需要输出作为A-headh2级别部分,B-Head作为h3子级别部分h2C-Head作为h4子级别部分h3D-Head作为h5子级别部分h4E-Head作为h6子级别部分h5F-Head作为h6相同级别部分,h6如下所示:

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en-us" lang="en">
    <head>
        <title>Heading</title>
    </head>
    <body class="Section" id="topic_1">
        <section>
            <p class="TitleTtl">Heading2</p>
            <h2>A-Head</h2>
            <section>
                <p class="p">Some paragraph text</p>
                <h3>B-Head</h3>
                <section>
                    <p class="p">Some more paragraph text</p>
                    <h4>C-Head</h4>
                    <section>
                        <p class="p">Yet more paragraph text</p>
                        <h5>D-Head</h5>
                        <section>
                            <p class="p">Some creative paragraph text</p>
                            <h6>E-Head</h6>
                            <section>
                                <p class="p">Now, boing paragraph text</p>
                            </section>
                            <h6>F-Head</h6>
                            <section>
                                <p class="p">Finally, end</p>
                            </section>
                        </section>
                    </section>
                </section>
            </section>
        </section>
    </body>
</html>

请建议。

提前致谢

4

0 回答 0