Subject: Re: [xsl] xsl:for-each-group output control From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 23 Nov 2007 22:34:00 GMT |
your output this time doesn't match your input (dufferent texts) and last time you said the output should look like this: ... <sect1> <h3>h3_1</h3> but this time you show title elements not h3. You realy make it hard for anyone to help, but I guess something like this <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="root"> <set> <xsl:apply-templates select="element"/> </set> </xsl:template> <xsl:template match="element"> <book> <bookinfo/> <xsl:call-template name="group"/> </book> </xsl:template> <xsl:template name="group"> <xsl:param name="l" select="1"/> <xsl:param name="nodes" select="*"/> <xsl:for-each-group select="$nodes" group-starting-with="*[name()=concat('h',$l)]"> <xsl:choose> <xsl:when test="name()=concat('h',$l)"> <xsl:element name="{if($l=1)then 'chapter' else concat('sect',$l - 1)}"> <title> <xsl:apply-templates/> </title> <xsl:call-template name="group"> <xsl:with-param name="l" select="$l+1"/> <xsl:with-param name="nodes" select="current-group()[position()!=1]"/> </xsl:call-template> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="."/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> which makes <?xml version="1.0" encoding="UTF-8"?> <set> <book> <bookinfo/> <chapter> <title>h1</title> <sect1> <title>h2_1</title> <para>para_1</para> </sect1> <sect1> <title>h2_2</title> <para>para_6</para> <sect2> <title>h3_1</title> <para>para_7</para> <sect3> <title>h4_1</title> <para>para_11</para> </sect3> </sect2> </sect1> <sect1> <title>h2_3</title> <para>para_13</para> <sect2> <title>h3_2</title> <para>para_16<emp>auszeichnung</emp> </para> <sect3> <title>h4_2</title> <para>para_19</para> <sect4> <title>h5_2</title> <para>para_21</para> </sect4> </sect3> </sect2> </sect1> </chapter> </book> </set> David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xsl:for-each-group output, Andreas Peter | Thread | Re: [xsl] xsl:for-each-group output, David Carlisle |
Re: [xsl] xsl:for-each-group output, Andreas Peter | Date | Re: [xsl] xsl:for-each-group output, David Carlisle |
Month |