[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: transform html h1 with a div


Subject: [xsl] Re: transform html h1 with a div
From: Giuseppe Briotti <g.briotti@xxxxxxxxx>
Date: Wed, 31 Oct 2012 19:06:27 +0000 (UTC)

Michael Kay <mike <at> saxonica.com> writes:

> 
> 
> I'm not sure why you are going to such lengths to deal with missing 
> levels. Surely the standard code that simply processes levels h1, h2, 
> ... h6 in turn, recursively, will cope with missing levels without any 
> special code needed?
> 
> Michael Kay
> Saxonica

Hi Michael, the problem is that I must process fragment of html too. This means
that I can have situation like the following:

<h3>Title 3</h3>
<p>bla bla bla</p>
<p>bla bla bla</p>
<h2>Title 2</h2>
<p>bla bla bla</p>
<p>bla bla bla</p>
<h3>Title 3</h3>
<p>bla bla bla</p>
<p>bla bla bla</p>
<h4>Title 4</h4>
<p>bla bla bla</p>
<p>bla bla bla</p>

that should be nested as:

<div class="h3">
<h3>Title 3</h3>
<p>bla bla bla</p>
<p>bla bla bla</p>
</div>

<div class="h2">
<h2>Title 2</h2>
<p>bla bla bla</p>
<p>bla bla bla</p>

<div class="h3">
<h3>Title 3</h3>
<p>bla bla bla</p>
<p>bla bla bla</p>

<div class="h4">
<h4>Title 4</h4>
<p>bla bla bla</p>
<p>bla bla bla</p>
</div>

</div>

</div>

This means that I cannot start basically with h1 to h6, but I must choose a more
complex strategy in grouping and then process recursively each starting group.
In the above example, the first "starting group" is the first h3, the second one
is the h2 ("containing" the second h3 and h4) that must be processed recursively
to create the second h3 and h4 div.

Applying a pattern with for-each-group with group-starting-with works fine to
select the topmost group, the problem is because the involving preceding-sibling
it, of course, doesn't work on subsequent deepest current-group()...

Giuseppe.


Current Thread