Re: [xsl] Transforming XML Blockquotes - Mixed Content

Subject: Re: [xsl] Transforming XML Blockquotes - Mixed Content
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 14 Apr 2005 09:52:43 +0100
The mathml spec stylesheets (available in the sources zip file linked
from 
http://www.w3.org/TR/mathml2
do the following to stop p elements in the source at a range of block
level elements and split up the resulting p so the html is bvaild and
only has inline elemments.


<xsl:template match="p">
  <xsl:apply-templates select="." mode="p">
    <xsl:with-param name="x" 
         select="count(eg|glist|olist|ulist|slist|orglist|
                       table|issue|note|processing-instruction()|
                       graphic[not(@role='inline')])" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template mode="p" match="p">
<xsl:param name="x"/>
  <p>
  <xsl:apply-templates 
    select="node()[not(self::eg or self::glist or self::olist or
                       self::ulist or self::slist or self::orglist or
                       self::table or self::issue or self::note or
                       self::processing-instruction() or
                       self::graphic[not(@role='inline')]) and
    count(following-sibling::*[self::eg or self::glist or self::olist or
                               self::ulist or self::slist or self::orglist or
                               self::table or self::issue or self::note or
                               self::processing-instruction() or
                               self::graphic[not(@role='inline')] ])
         = $x]" />
  </p>
  <xsl:apply-templates
       select="(eg|glist|olist|ulist|slist|orglist|
                table|issue|note|processing-instruction()|
                graphic[not(@role='inline')])
                  [position() = last() - $x + 1]"/>
  <xsl:if test="$x &gt; 0">
    <xsl:apply-templates select="." mode="p">
      <xsl:with-param name="x" select="$x - 1" />
    </xsl:apply-templates>
  </xsl:if>
</xsl:template>


The code is rather old (Older than XSLT 1.0, in fact) today I;d probably
optimise it a bit with a key but unless your paragraphs have thousands
of child elements optimisation probaby isn't really important.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread