xsl-list
[Top] [All Lists]

RE: [xsl] Grouping a sequence of elements in different ways in the same stylesheet

2010-05-21 16:49:30
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[(_at_)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(_dot_)desjardins(_dot_)us(_at_)gmail(_dot_)com] 
Sent: 21 May 2010 22:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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[(_at_)class='head1']" >
        <xsl:apply-templates select="." mode="group-level-one"/>
    </xsl:for-each-group>
</xsl:template>

Thanks for your help.

Peter

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>