В кратком ответе эта таблица стилей:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="section">
<xsl:for-each-group select="node()" group-starting-with="h1">
<xsl:result-document href="{@scriptlabel}.inc">
<xsl:copy-of select="current-group()"/>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
Сериализуйте это Gov-chairman-intro.inc
:
<h1 charstyle="No Style"
pagenum="56"
parastyle="Gov-Head-A"
scriptlabel="Gov-chairman-intro"
>chairman’s introduction</h1>
<p charstyle="No Style"
pagenum="56"
parastyle="Gov–Head-B-CI"
scriptlabel="">
<strong charstyle="No Style"
pagenum="56"
parastyle="Gov–Head-B-CI"
scriptlabel=""
>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi et leo purus. Maecenas at metus massa. Donec rutrum tortor ac enim tincidunt ut posuere purus aliquam.</strong>
</p>
<p charstyle="No Style"
pagenum="56"
parastyle="Gov-Body-CI"
scriptlabel=""
>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi et leo purus. Maecenas at metus massa. Donec rutrum tortor ac enim tincidunt ut posuere purus aliquam.</p>
Примечание: Группировка section
детей по началу h1
. Копирование всей текущей группы.
Обновление : Работа с section
без h1
дочернего элемента, а также без запуска h1
группы.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="section">
<xsl:for-each-group select="*" group-adjacent="boolean(self::h1)">
<xsl:if test="not(current-grouping-key())">
<xsl:variable name="vMark" select="preceding-sibling::h1[1]"/>
<xsl:result-document
href="{((..|$vMark)/@scriptlabel)[last()]}.inc">
<xsl:copy-of select="current-group()|$vMark"/>
</xsl:result-document>
</xsl:if>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
С этим входом:
<document>
<section charstyle="No Style" pagenum="56" parastyle="Gov-Head-A"
scriptlabel="Gov-chairman-intro">
<h1 charstyle="No Style" pagenum="56" parastyle="Gov-Head-A"
scriptlabel="Gov-chairman-intro">chairman’s
introduction</h1>
<p charstyle="No Style" pagenum="56"
parastyle="Gov–Head-B-CI" scriptlabel="">
<strong charstyle="No Style" pagenum="56"
parastyle="Gov–Head-B-CI" scriptlabel=""
>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi et leo purus. Maecenas at metus massa. Donec
rutrum tortor ac enim tincidunt ut posuere purus
aliquam.</strong>
</p>
<p charstyle="No Style" pagenum="56" parastyle="Gov-Body-CI"
scriptlabel="">Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Morbi et leo purus. Maecenas at metus
massa. Donec rutrum tortor ac enim tincidunt ut posuere
purus aliquam.</p>
</section>
<section charstyle="No Style" pagenum="56" parastyle="Gov-Head-A"
scriptlabel="Test-no-H1">
<p charstyle="No Style" pagenum="56"
parastyle="Gov–Head-B-CI" scriptlabel="">
<strong charstyle="No Style" pagenum="56"
parastyle="Gov–Head-B-CI" scriptlabel=""
>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi et leo purus. Maecenas at metus massa. Donec
rutrum tortor ac enim tincidunt ut posuere purus
aliquam.</strong>
</p>
<p charstyle="No Style" pagenum="56" parastyle="Gov-Body-CI"
scriptlabel="">Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Morbi et leo purus. Maecenas at metus
massa. Donec rutrum tortor ac enim tincidunt ut posuere
purus aliquam.</p>
</section>
</document>
Правильно сериализовать Gov-chairman-intro.inc
<h1 charstyle="No Style" pagenum="56" parastyle="Gov-Head-A" scriptlabel="Gov-chairman-intro">chairman’s
introduction</h1><p charstyle="No Style" pagenum="56" parastyle="Gov–Head-B-CI" scriptlabel=""><strong charstyle="No Style" pagenum="56" parastyle="Gov–Head-B-CI" scriptlabel="">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi et leo purus. Maecenas at metus massa. Donec
rutrum tortor ac enim tincidunt ut posuere purus
aliquam.</strong></p><p charstyle="No Style" pagenum="56" parastyle="Gov-Body-CI" scriptlabel="">Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Morbi et leo purus. Maecenas at metus
massa. Donec rutrum tortor ac enim tincidunt ut posuere
purus aliquam.</p>
А Test-no-H1.inc
<p charstyle="No Style" pagenum="56" parastyle="Gov–Head-B-CI" scriptlabel=""><strong charstyle="No Style" pagenum="56" parastyle="Gov–Head-B-CI" scriptlabel="">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi et leo purus. Maecenas at metus massa. Donec
rutrum tortor ac enim tincidunt ut posuere purus
aliquam.</strong></p><p charstyle="No Style" pagenum="56" parastyle="Gov-Body-CI" scriptlabel="">Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Morbi et leo purus. Maecenas at metus
massa. Donec rutrum tortor ac enim tincidunt ut posuere
purus aliquam.</p>
Примечание : группа примыкает к "Я знак?", Копировать группу и предшествующий знак.