Hello List!
Unfortunaltely I still have a problem with xsl:for-each-group and my
xml example.
For a better understanding the test-xml-file:
<root>
<element>
<h1>h1</h1>
<h2>h2_1</h2>
<para>para_1</para>
<para>para_2<emp>auszeichnung</emp></para>
<para>para_3</para>
<para>para_4</para>
<para>para_5</para>
<h2>h2_2</h2>
<para>para_6</para>
<h3>h3_1</h3>
<para>para_7</para>
<h5>h5_1</h5>
<para>para_8</para>
<para>para_9<emp>auszeichnung</emp></para>
<para>para_10</para>
<h4>h4_1</h4>
<para>para_11</para>
<para>para_12</para>
<h2>h2_3</h2>
<para>para_13</para>
<para>para_14</para>
<para>para_15</para>
<h3>h3_2</h3>
<para>para_16<emp>auszeichnung</emp></para>
<para>para_17</para>
<para>para_18</para>
<h4>h4_2</h4>
<para>para_19</para>
<para>para_20</para>
<h5>h5_2</h5>
<para>para_21</para>
<para>para_22<emp>auszeichnung</emp></para>
<para>para_23</para>
</element>
</root>
I numbered the text nodes for a better visualization.
I try to use the following xsl file:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<set>
<book>
<bookinfo/>
<xsl:apply-templates/>
</book>
</set>
</xsl:template>
<xsl:template match="element">
<xsl:apply-templates select="h1|h2[1]"/>
</xsl:template>
<xsl:template match="h1">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>
<xsl:template match="h2">
<xsl:for-each-group select=".|following-sibling::*"
group-starting-with="h2|h3|h4|h5">
<xsl:choose>
<xsl:when test="current-group()[self::h2]">
<chapter>
<title>
<xsl:apply-templates/>
</title>
<xsl:copy-of select="current-group()[self::para]"/>
<xsl:choose>
<xsl:when
test="current-group()[following-sibling::h3]">
<xsl:call-template name="h3"/>
</xsl:when>
</xsl:choose>
</chapter>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="h3">
<sect1>
<title>
<xsl:apply-templates/>
</title>
<xsl:copy-of select="current-group()[self::para]"/>
</sect1>
</xsl:template>
</xsl:stylesheet>
My output looks like this:
<set>
<book>
<bookinfo/>
<title>h1</title>
<chapter>
<title>h2_1</title>
<para>para_1</para>
<para>para_2<emp>auszeichnung</emp>
</para>
<para>para_3</para>
<para>para_4</para>
<para>para_5</para>
<sect1>
<title>h2_1</title>
<para>para_1</para>
<para>para_2<emp>auszeichnung</emp>
</para>
<para>para_3</para>
<para>para_4</para>
<para>para_5</para>
</sect1>
</chapter>
<chapter>
<title>h2_2</title>
<para>para_6</para>
<sect1>
<title>h2_2</title>
<para>para_6</para>
</sect1>
</chapter>
<chapter>
<title>h2_3</title>
<para>para_13</para>
<para>para_14</para>
<para>para_15</para>
<sect1>
<title>h2_3</title>
<para>para_13</para>
<para>para_14</para>
<para>para_15</para>
</sect1>
</chapter>
</book>
</set>
But instead of
...
<sect1>
<title>h2_1</title>
<para>para_1</para>
<para>para_2<emp>auszeichnung</emp></para>
<para>para_3</para>
<para>para_4</para>
<para>para_5</para>
</sect1>
...
the output should look like this:
...
<sect1>
<h3>h3_1</h3>
<para>para_7</para>
</sect1>
...
and so on. Unfortunately I cannot see the problem. Isn´t it possible
to grab the content out of a xsl:for-each-group as I tried it using a
separate template?
I am really sorry for that perhaps basic question but I am dispaired
about that problem.
Thanks for helping me. Perhaps one day I will be more firm to XSLT.
Andreas
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--