Print

Print


At 04:54 AM 2/1/2005, Michael wrote:
>  The later grouped <p>s would
>still then all emerge fine, but not before the faith of any reasonable
>person in my competence, or the usability of XSLT, or maybe both, had been
>badly shattered.

Maybe so, people's expectations of magic being what they are, but I say
"Feh". Bugs, and the need to fix them, are what software development is all
about.

I'd also be curious to know if Michael or anyone has worked out an XSLT 2.0
solution. The grouping constructs there should be a big help. I haven't,
yet -- no time to give (*sigh*).

The forward-stepping approach I mentioned earlier is also worth taking a
look at:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <xsl:template match="p">
     <p>
       <xsl:apply-templates select="node()[1]" mode="tuck"/>
     </p>
     <xsl:apply-templates select="q[@rend='blockquote'][1]"/>
   </xsl:template>

   <xsl:template match="q[@rend='blockquote']" mode="tuck"/>

   <xsl:template match="node()" mode="tuck">
     <xsl:apply-templates select="."/>
     <xsl:apply-templates select="following-sibling::node()[1]" mode="tuck"/>
   </xsl:template>

   <xsl:template match="p/q[@rend='blockquote']">
     <div class="blockquote">
       <xsl:apply-templates/>
     </div>
     <xsl:apply-templates select="following-sibling::node()[1]"
mode="tuck-again"/>
   </xsl:template>

   <xsl:template match="node()" mode="tuck-again">
     <p>
       <xsl:apply-templates select="." mode="tuck"/>
     </p>
     <xsl:apply-templates
select="following-sibling::q[@rend='blockquote'][1]"/>
   </xsl:template>

   <xsl:template match="p/q[@rend='blockquote']" mode="tuck-again">
     <xsl:apply-templates select="."/>
   </xsl:template>

   <xsl:template match="*">
     <xsl:copy>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

Unfortunately I have no time today to provide color commentary -- but to
give a hint as to how it works, this "forward walk" has also been called
the "tree visitor pattern". As far as XSLT orthodoxy is concerned, it's
probably in between Michael's grouping solution and the heresy of d-o-e
tag-writing. The grouping solution is "classic", while this bends the rules
by taking over the job of tree traversal from the processor's default
approach, instead handling it explicitly in the code.

(Note also I have not stress-tested this: the usual non-warrants apply.)

I saw it first from Mike Kay, but I think he might have gotten it from Jeni
Tennison. Or some other smart XSLTer who was not lucky enough to get her
name attached to it.

FWIW, on the tag-semantics issue: I think the breakout problem arises from
clashing definitions of the paragraph as logical or renditional. The most
correct transform, from the semantic point of view, from TEI "true"
paragraphs into HTML might result in:

<div class="paragraph">
   <p class="pseudo-paragraph">...</p>
   <div class="block-level">...</div>
   <p class="pseudo-paragraph">...</p>
</div>

(This would be done straightforwardly by an easy extension to the code above.)

Cheers,
Wendell


======================================================================
Wendell Piez                            mailto:[log in to unmask]
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================