Re: [xsl] Transform inline-block type elements to block-level elements

Subject: Re: [xsl] Transform inline-block type elements to block-level elements
From: "Christian Roth" <roth@xxxxxxxxxxxxxx>
Date: Thu, 30 Nov 2006 22:18:30 +0100
David Carlisle wrote:

>You'd be better with something like the following.
>[nice XSLT solution snipped]

Thanks David! Wanted to post this much earlier, but did not get the time.

I had created another solution about the time you posted yours, but
which I think takes a way more awkward route (though I see both
solutions use a temporary element wrapper for text nodes resp. non-
element nodes and we both make copies or references to the original
nodes to work on), with some benefits thrown in.

The difference to your solution seems to be that I am flattening the
tree completely, attaching nesting level information as attributes, and
then group on this, and that I am not using dedicated templates for the
elements, but use a single variable for storing the block-level elements
to work on. I have extended the XSLT in such a way that it can cope with
any (unknown in advance) inlines plus any set attributes, empty elements
and PIs in a generic way.

I think mixing both of our approaches could yield something usable. :-)

The sample XML, my XSLT code and the intended result is available from here:


(I decided to put it online and not inline since some of the XPath
expressions are longer than can be swiftly handled within email's 80
char lien width limit.)

It also provides some first step at a solution for Andreas.M's question
you referred to (<
msg00744.html>), just use a configuration in the XSLT similar to this one:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""; 
  exclude-result-prefixes="cr xs"

  <xsl:strip-space elements="*"/>

  <xsl:param name="blocknames" select="(
    QName('', 'draw:frame'),
    QName('', 'draw:image'),

    QName('', 'text:h'),
    QName('', 'text:p')
    )" />

  <xsl:template match="root">
  <xsl:template match="text:h|text:p">
    <xsl:call-template name="block-root">
      <xsl:with-param name="grouping-element" select="$grouping-element"


Well, if it isn't useful in any other way, then it's at least an example
of horrible XSLT code...


Current Thread