[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: xslt 2.0: grouping flat element structures to make
Thanks for the solution David Carlisle, this certainly does the flat-to-grouped job I need. However, one more query (open to anyone): Would I need to add this grouping processing approach to ALL the possible parent elements that the flat-list structures can occur in? In my DTD there are many parent element possibilities and what's more many already have a fair amount of complex code in their templates (don't want to upset this if I can avoid it). That's why I tried to use the first <par class="Listbegin"> as a kind of trigger for the list processing. Is this route not the one to take due to XSLT processing model? Goal (<Any-element> is a wildcard and not necessarily the root): <?xml version="1.0" encoding="UTF-8"?> <Any-element> <a>some text</a> <par class="Listbegin">Fruit</par> <par class="Listitem>Apple</par> <par class="Listitem>Orange</par> <par class="Listitem>Pear</par> <a>more text</a> <par class="Listbegin">Colours</par> <par class="Listitem>Red</par> <par class="Listitem>Green</par> <par class="Listitem>Blue</par> <par class="Listbegin">Shapes</par> <par class="Listitem>Triangle</par> <par class="Listitem>Circle</par> <par class="Listitem>Square</par> <a>yet more text</a> </Any-element> to produce <?xml version="1.0" encoding="UTF-8"?> <data> <a>some text</a> <list> <head>Fruit</head> <item>Apple</item> <item>Orange</item> <item>Pear</item> </list> <a>more text</a> <list> <head>Colours</head> <item>Red</item> <item>Green</item> <item>Blue</item> </list> <list> <head>Shapes</head> <item>Triangle</item> <item>Circle</item> <item>Square</item> </list> <a>yet more text</a> </data> Thanks Derek Revill > -----Original Message----- > From: David Carlisle [mailto:davidc@xxxxxxxxx] > Sent: 25 May 2005 22:30 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: xslt 2.0: grouping flat element structures to make > lists > > > > <sect> > > <foo/> > <xyz/> > <xyz/> > <par class="Listbegin">Fruit</par> > <par class="Listitem">Apple</par> > <par class="Listitem">Orange</par> > <par class="Listitem">Pear</par> > <par class="Listbegin">Colours</par> > <par class="Listitem">Red</par> > <par class="Listitem">Green</par> > <par class="Listitem">Blue</par> > <xyz/> > <bar/> > <par class="Listbegin">Fruit</par> > <par class="Listitem">Apple</par> > <par class="Listitem">Orange</par> > <par class="Listitem">Pear</par> > </sect> > > > > <xsl:stylesheet > version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > > > > <xsl:output indent="yes"/> > > <xsl:template match="*"> > <xsl:copy> > <xsl:copy-of select="@*"/> > <xsl:apply-templates/> > </xsl:copy> > </xsl:template> > > <xsl:template match="sect"> > <xsl:copy> > <xsl:copy-of select="@*"/> > <xsl:for-each-group group-adjacent="@class='Listitem'" select="*"> > <xsl:choose> > <xsl:when test="self::par[@class='Listitem']"> > <list> > <head><xsl:apply-templates > select="preceding-sibling::par[1]/node()"/></head> > <xsl:apply-templates select="current-group()"/> > </list> > </xsl:when> > <xsl:otherwise> > <xsl:apply-templates select="current-group()"/> > </xsl:otherwise> > </xsl:choose> > </xsl:for-each-group> > </xsl:copy> > </xsl:template> > > <xsl:template match="par[@class='Listbegin']"/> > > > </xsl:stylesheet> > > > > $ saxon8 list.xml list.xsl > <?xml version="1.0" encoding="UTF-8"?> > <sect> > <foo/> > <xyz/> > <xyz/> > <list> > <head>Fruit</head> > <par class="Listitem">Apple</par> > <par class="Listitem">Orange</par> > <par class="Listitem">Pear</par> > </list> > <list> > <head>Colours</head> > <par class="Listitem">Red</par> > <par class="Listitem">Green</par> > <par class="Listitem">Blue</par> > </list> > <xyz/> > <bar/> > <list> > <head>Fruit</head> > <par class="Listitem">Apple</par> > <par class="Listitem">Orange</par> > <par class="Listitem">Pear</par> > </list> > </sect> > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________
|
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
|