需要将paras作为以h级别为标题的主和子级别

时间:2018-07-06 12:30:13

标签: xslt dita dita-ot

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

我的输入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-head作为h2主级别部分的输出,将B-Head作为h3子级别部分的h2C-Head的输出h4的{​​{1}}子级别部分,h3的{​​{1}}子级别部分,D-Head子级别的h5对于h4E-Headh6h5处于同一级别,如下所示:

F-Head

请提出建议。

预先感谢

0 个答案:

没有答案