RE: [xsl] Flat to Structured: Handling List Items with Subordinate Paragraphs

Subject: RE: [xsl] Flat to Structured: Handling List Items with Subordinate Paragraphs
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 26 May 2009 22:20:52 +0100
> For example, I could have an ordered list followed by an 
> unordered list, which would give a group like:
> 
> <p type="li" container="ol" level="1">
> <p type="p" container="li" level="2">
> <p type="li" container="ol" level="1">
> <p type="p" container="li" level="2">
> <p type="li" container="ul" level="1">
> <p type="p" container="li" level="2">
> 
> Where the result should be:
> 
> <ol>
>   <li>
>     <p>
>   </li>
>   <li>
>     <p>
>   <li>
> </ol>
> <ul>
>   <li>
>    <p>
>   <li>
> </ul>
> 
> I don't see a way to get that result using 
> group-starting-with on the group members.
> 

I haven't followed the thread closely, but I would tackle the above by first
using group-starting with to build the levels

<xsl:for-each-group select="*" group-starting-with="*[@level='1']">

applied recursively if necessary for each level, giving

<p type="li" container="ol" level="1">
  <p type="p" container="li" level="2">
</p>
<p type="li" container="ol" level="1">
  <p type="p" container="li" level="2">
</p>
<p type="li" container="ul" level="1">
  <p type="p" container="li" level="2">
</p>

and then apply group-adjacent to the level 1's (and perhaps recursively to
each level?):

<xsl:for-each-group select="*" group-adjacent="@container">
  <xsl:element name="{current-grouping-key()}">
    <xsl:copy-of select="current-group()"/>
  </
</

to give your required structure, with a bit of trivial tweaking needed to
change <p type="li"> to <li>.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread