Hello list!
I try to solve a problem by my own which Ken G. Holman solved
fortunately solved a few days ago. But for improving my not really
destinctive XSLT skills I tried to solve the problem by my own. But
now I am fighting with the problem again. I hope the list will be not
too impatient with me :-)
Here is the flat XML-code:
<Root>
<element>
<h1>h1</h1>
<h2>h2_1</h2>
<para>para_h2_1</para>
<para>para_h2_1</para>
<para>para_h2_1</para>
<para>para_h2_1</para>
<para>para_h2_1</para>
<para>para_h2_1</para>
<para>para_h2_1</para>
<h2>h2_2</h2>
<h3>h3_1</h3>
<para>para_h3_1</para>
<h4>h4_1</h4>
<h5>h5_1</h5>
<para>para_h5_1</para>
<h5>h5_2</h5>
<note>note_h5_2</note>
<para>para_h5_2</para>
<h4>h4_2</h4>
<para>para_h4_2</para>
<para>para_h4_2</para>
<para>para_h4_2</para>
<note>note_h4_2</note>
<h3>h3_2</h3>
<para>para_h3_2</para>
<para>para_h3_2</para>
<para>para_h3_2</para>
<h4>h4_3</h4>
<para>para_h4_3</para>
<para>para_h4_3</para>
<para>para_h4_3</para>
<h5>h5_3</h5>
<para>para_h5_3</para>
<para>para_h5_3</para>
</element>
</Root>
I am using this stylesheet for transformations:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<set>
<book>
<bookinfo/>
<author/>
<xsl:apply-templates/>
</book>
</set>
</xsl:template>
<xsl:template match="Root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="element">
<title>
<xsl:apply-templates select="h1"/>
</title>
<chapter>
<xsl:apply-templates select="h2[1]"/>
</chapter>
</xsl:template>
<xsl:template match="h2">
<title>
<xsl:apply-templates/>
</title>
<xsl:for-each-group select="following-sibling::*"
group-starting-with="h2|h3|h4|h5">
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="h3">
<xsl:element name="sect{number(substring-after(name(.),'h')) - 2}">
<title>
<xsl:apply-templates/>
</title>
<para>
<xsl:apply-templates
select="current-group()[self::para]/node()"/>
</para>
</xsl:element>
</xsl:template>
<xsl:template match="h4">
<xsl:element name="sect{number(substring-after(name(.),'h')) - 2}">
<title>
<xsl:apply-templates/>
</title>
<xsl:for-each select="current-group()[para]">
<para>
<xsl:apply-templates
select="current-group()[self::para]/node()"/>
</para>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="h5">
<xsl:element name="sect{number(substring-after(name(.),'h')) - 2}">
<title>
<xsl:apply-templates/>
</title>
<para>
<xsl:apply-templates
select="current-group()[self::para]/node()"/>
</para>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
But something is wrong with it but I cannot see the mistake at the
moment. My problem is, that the textnodes are outputted after every
<sectxx>. This should come from the <xsl:apply-templates
select="current-group()"/> but I donnot really want them to be
displayed.
I would be very thankful for every hint from the experts.
Thanks,
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>
--~--