xslt - 需要 paras 作为部分主级别和子级别标题与 h 级别
问题描述
具有不同输出类的 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-head
主h2
级别部分,B-Head
作为h3
子级别部分h2
,C-Head
作为h4
子级别部分h3
,D-Head
作为h5
子级别部分h4
,E-Head
作为h6
子级别部分h5
,F-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>
请建议。
提前致谢
解决方案
推荐阅读
- javascript - 如何根据服务器对数据进行分组并获取最新数据
- c++ - JNI 日期值转换问题,在 C++ 中获得不同的长值
- php - 从重写 htaccess 中排除文件和文件夹
- c# - 如何使用动态参数在 web.config 文件中设置重定向?
- c# - GET 和 POST 的 Asp.Net 文化不同
- android - 如何将 Material Button ShapeAppearance 与 Edittext Shape Appearance 分开?
- flutter - Flutter Provider:“ProxyFutureProvider”或类似的
- angular - 请参阅 Angular 8 中强类型列表中的 FormBuilder 成员
- c# - 如何模拟一个有输入的函数是一个例外?
- c - 在 SwiftUI 中,我将如何创建一个将项目添加到 ScrollView 的函数?