XSLT 2.0 で xsl:for-each を使用して要素をグループ化しようとしています。
これが私の入力の実例です:
<root>
<chapter>
<heading> heading text </heading>
<title> title </title>
<p> 1111 </p>
<p> 2222 </p>
<center> text </center>
<p> 3333 </p>
<title> another title </title>
<p> 4444 </p>
<center> text </center>
<p> 5555 </p>
</chapter>
<chapter>
<heading> heading text </heading>
<title> another title </title>
<p> 6666 </p>
<p> 7777 </p>
<title> another title </title>
<p> 8888 </p>
<p> 9999 </p>
</chapter>
<root>
<title>
各要素を照合し、次の要素まで次のすべての要素を要素にグループ化することにより、このドキュメントをグループ化しようとして<title>
います<section>
。出力を次のように表示します。
<root>
<chapter>
<heading> Heading text </heading>
<section>
<title> title </title>
<p> 1111 </p>
<p> 2222 </p>
<center> text </center>
<p> 3333 </p>
</section>
<section>
<title> title </title>
<p> 4444 </p>
<center> text </center>
<p> 5555 </p>
</section>
<section>
<title> title </title>
<p> 6666 </p>
<p> 7777 </p>
<center> text </center>
<p> 8888 </p>
<p> 9999 </p>
</section>
<chapter>
<root>
機能していない現在のテンプレート:
<xsl:template match="chapter">
<chapter>
<xsl:for-each-group select="*" group-starting-with="title">
<section>
<xsl:copy-of select="current-group()" />
</section>
</xsl:for-each-group>
</chapter>
</xsl:template>
上記のスタイルシートは、必要なセクションをグループ化しますが、何らかの理由で各<heading>
要素を独自にグループ化します。<section>
助言がありますか?
前もって感謝します。