[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT 2.0 & Grouping for-each-group
* Michael Kay
<snip> ... with xsl:variable name="next" select="*[1]/@StyleName" xsl:for-each-group group-starting-with="*[@StyleName=$next]" This also has the advantage that it's the same code at all levels. </snip> * Mark Brand Hi Michael This change unless I have made an error in coding (but how hard can it be to cut and paste;-)) has caused a problem it is only picking up the first Grouping (i think). The code after the change is in Listing 1 below. Listing 2 is the input doc., Listing 3 is the output from the program prior to the $next change and Listing 4 is the output after the $next change. If you have any further suggestions .... Thanks Mark ================================================================= Listing 1 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:template match="Document/DocumentBody"> <Regulation> <xsl:variable name="next" select="*[1]/@StyleName"/> <xsl:for-each-group select="Paragraph" group-starting-with="*[@StyleName=$next]"> <Part> <xsl:copy-of select="child::node()"/> <xsl:variable name="next" select="*[1]/@StyleName"/> <xsl:for-each-group select="current-group() except ." group-starting-with="*[@StyleName=$next]"> <Division> <xsl:copy-of select="child::node()"/> <xsl:variable name="next" select="*[1]/@StyleName"/> <xsl:for-each-group select="current-group() except ." group-starting-with="*[@StyleName=$next]"> <Article> <xsl:copy-of select="child::node()"/> <xsl:variable name="next" select="*[1]/@StyleName"/> <xsl:for-each-group select="current-group() except ." group-starting-with="*[@StyleName=$next]"> <Sub-Article> <xsl:copy-of select="child::node()"/> </Sub-Article> </xsl:for-each-group> </Article> </xsl:for-each-group> </Division> </xsl:for-each-group> </Part> </xsl:for-each-group> </Regulation> </xsl:template> </xsl:stylesheet> ================================================================= Listing 2 <?xml version="1.0" encoding="ISO-8859-1"?> <Document> <DocumentBody> <Paragraph StyleName="PART"> <Text>Part 1 Preliminary</Text> </Paragraph> <Paragraph StyleName="DIVISION"> <Text>Division 1.1 Introductory</Text> </Paragraph> <Paragraph StyleName="REGULATION"> <Text>1.01 Name of <em>Regulations</em> [see Note 1]</Text> </Paragraph> <Paragraph StyleName="SUB-REGULATION"> <Text> These Regulations are the Migration Regulations 1994</Text> </Paragraph> <Paragraph StyleName="SUB-REGULATION"> <Text> These Regulations are the Migration Regulations 1995</Text> </Paragraph> <Paragraph StyleName="REGULATION"> <Text>1.02 Commencement</Text> </Paragraph> <Paragraph StyleName="SUB-REGULATION"> <Text> These Regulations commence on 1 September 1994.</Text> </Paragraph> <Paragraph StyleName="SUB-REGULATION"> <Text> These Regulations commence on 1 September 1995.</Text> </Paragraph> <Paragraph StyleName="DIVISION"> <Text>Division 1.2 Interpretation</Text> </Paragraph> </DocumentBody> </Document> ================================================================= Listing 3 <?xml version="1.0" encoding="UTF-8"?> <Regulation> <Part> <Text>Part 1 Preliminary</Text> <Division> <Text>Division 1.1 Introductory</Text> <Article> <Text>1.01 Name of <em>Regulations</em> [see Note 1]</Text> <Sub-Article> <Text> These Regulations are the Migration Regulations 1994</Text> </Sub-Article> <Sub-Article> <Text> These Regulations are the Migration Regulations 1995</Text> </Sub-Article> </Article> <Article> <Text>1.02 Commencement</Text> <Sub-Article> <Text> These Regulations commence on 1 September 1994.</Text> </Sub-Article> <Sub-Article> <Text> These Regulations commence on 1 September 1995.</Text> </Sub-Article> </Article> </Division> <Division> <Text>Division 1.2 Interpretation</Text> </Division> </Part> </Regulation> ================================================================= Listing 4 <?xml version="1.0" encoding="UTF-8"?> <Regulation> <Part> <Text>Part 1 Preliminary</Text> <Division> <Text>Division 1.1 Introductory</Text> <Article> <Text>1.01 Name of <em>Regulations</em> [see Note 1]</Text> <Sub-Article> <Text> These Regulations are the Migration Regulations 1994</Text> </Sub-Article> </Article> </Division> </Part> </Regulation> ================================================================= Michael Kay wrote: Perhaps you could replace XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|