[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Wrap changing element sequence into container: wit
Thank you very much for both suggestions. So if I understand right I
either have to resort to something which looks to me like "recursion
into groups", applying xsl:for-each-group to the result of all previous
groupings, or I have to set up a kind of table of grouping keys on which
to branch.
A third approach came to my mind. When the order of elements in the flat sequence is fixed, the series of xsl:apply-templates instructions that process the remaining elements may be interrupted by the necessary xsl:for-each-group instructions, which then can immediately select the elements they have to group. Like this: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="root"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="flatsequence"> <hierarchy> <xsl:apply-templates select="a"/> <xsl:for-each-group select="b|c" group-adjacent="1"> <container1> <xsl:copy-of select="current-group()"/> </container1> </xsl:for-each-group> <xsl:apply-templates select="d|e|f"/> <xsl:for-each-group select="g|h|i" group-adjacent="1"> <container2> <xsl:copy-of select="current-group()"/> </container2> </xsl:for-each-group> <xsl:apply-templates select="j"/> </hierarchy> </xsl:template> <xsl:template match="a|d|e|f|g|h|i|j"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> That seems to work, but perhaps I am missing something? (If it's OK as it is: any idea how to specify the grouping criterion, which just has to evaluate as permanently true, more elegantly than using 'group-adjacent="1"'?) Yves
|
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
|