[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Grouping a sequence of elements in different ways
I think the answer is to capture the result of the first grouping operation in a variable, and then apply the second operation to this variable. Somthing like: <xsl:template match = "body/div" > <xsl:variable name="temp" as="element()*"> <xsl:for-each-group select = "current-group()" group-adjacent = "name()='p' and @class='bulletedlist'"> <xsl:apply-templates select = "." mode = "itemizedlist" /> </xsl:for-each-group> </xsl:variable> <xsl:for-each-group select = "$temp" group-starting-with = "p[@class='head1']" > </xsl:for-each-group> </xsl:template> (But I haven't tried to understand the detail) Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: Peter Desjardins [mailto:peter.desjardins.us@xxxxxxxxx] > Sent: 21 May 2010 22:09 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Grouping a sequence of elements in different > ways in the same stylesheet > > Hi. I'm writing a 2.0 stylesheet to convert flat HTML to a > hierarchically structured XML format such as DocBook or DITA. > I'm new to XSLT. > > I need to group the HTML elements into <section> elements > according to heading levels (such as h1, h2, h3). I've got > that working using the group-starting-with attribute of > <xsl:for-each-group> thanks to help from this list. > > Now I need to wrap other sequences whenever they come up in > the source document. For example, whenever bulleted paragraph > styles occur, I need to group them in an <itemizedlist> > element. I can do this also with the group-adjacent attribute > of <xsl:for-each-group>. > > I've gotten stuck trying to group sections and itemized lists > at the same time. I need my stylesheet to pass through the > entire sequence of elements and perform grouping operations > as needed. If a bulleted list occurs at any point, group it. > If a h1, h2, or h3 element occurs, start a new group for a > <section> element. I'll also need to handle other types of > wrapping such as for numbered lists. > > Can anyone point me to an example of that sort of stylesheet? > One that performs several types of grouping during the same > pass over a sequence of elements? Here's an example of the > code I'm using. Both of the grouping operations will work if > I use them alone. > > <xsl:template match = "body/div" > > <xsl:for-each-group select = "current-group()" > group-adjacent = "name()='p' and @class='bulletedlist'"> > <xsl:apply-templates select = "." mode = "itemizedlist" /> > </xsl:for-each-group> > <!-- How do I perform both of these grouping operations > at the same time? --> > <xsl:for-each-group select = "*" group-starting-with = > "p[@class='head1']" > > <xsl:apply-templates select="." mode="group-level-one"/> > </xsl:for-each-group> > </xsl:template> > > Thanks for your help. > > Peter
|
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
|