Re: [xsl] List grouping

Subject: Re: [xsl] List grouping
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Fri, 27 Sep 2013 10:59:57 +0200
Ibd tackle it like this:

In a template that matches *[w:p], do an adjacent grouping of * with the key exists(w:pPr/w:listPr/w:ilvl/@w:val).

Then choose: when not(current-grouping-key()), pass the group unchanged. If current-grouping-key(), call a template or a function that youbll call recursively later on.

As xsl:param $elements, it takes the current-group().

First it calculates a variable $min as the min() of $elements/w:pPr/w:listPr/w:ilvl/@w:val (you might need to cast them as xs:double before applying min()).

Then it opens a list element. Within it, it groups the $elements, group-starting-with="*[number(w:pPr/w:listPr/w:ilvl/@w:val) = $min]".

Then a fringe case can happen: the first list items w:ilvl/@w:val is larger than $min. This means that the list starts with a 2nd-level 'a.' instead of a first-level '1.'. You can decide to handle this case, or you may just flag this as an input error.

In the normal case that each group indeed starts with the same level, create an li element, put the current-group()'s number and first and content in.

If there are more elements in the current-group(), call the template or the function on them, with elements = current-group()[position gt 1].

I hope it performs as expected and I didnbt put a mistake in. Writing and testing the actual XSLT code would probably have taken less time, but maybe itbs better for didactic reasons if you figure out the actual code yourself.


On 27.09.2013 08:43, Joga Singh Rawat wrote:

-----Original Message-----
From: Imsieke, Gerrit, le-tex [mailto:gerrit.imsieke@xxxxxxxxx]
Sent: Friday, September 27, 2013 12:08 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] List grouping

XSLT 1.0 or 2.0?

On 27.09.2013 07:11, Joga Singh Rawat wrote:
Dear List,

Anyone who can provide the idea to handle below list in worldml

<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
level</w:t></w:r></w:p> <w:p><w:pPr><w:listPr><w:ilvl w:val="1"/><wx:t
<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
level</w:t></w:r></w:p> <w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
wx:val="3."/></w:listPr></w:pPr><w:r><w:t>First lvel</w:t></w:r></w:p>

Should be

<li><num>1.</num><p>First level<p>
<li><num>a.</num><p>Second level<p></li> </list></li>
<li><num>2.</num><p>First level<p></li> <li><num>3.</num><p>First
level<p></li> </list>


-- Gerrit Imsieke GeschC$ftsfC<hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx,

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

GeschC$ftsfC<hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard VC6ckler

Current Thread