[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Transforming XML Blockquotes - Mixed Content - XSL

Subject: Re: Transforming XML Blockquotes - Mixed Content - XSLT 1.0 Solution
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 20 Apr 2005 22:45:19 +0100
david olist
>  The result it seems is a "powerful" 
> transformation standard that cannot easily transform something as simple as 
> a high school term paper or a newspaper article.

you are only talking about half a dozen lines of code, it's not exactly
complicated, even if it isn't necessarily obvious on first contact.

see for example the version I posted earlier, which may need changing to
match your particular input format but is a fairly generic way of
pulling block level elements out of a p

Date: 14 Apr 2005 09:52:43 +0100
From: David Carlisle <davidc@xxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
In-reply-to: <425DC386.3020209@xxxxxxxxxxxxxx> (message from James Fuller on
	Thu, 14 Apr 2005 03:12:38 +0200)
Subject: Re:  Transforming XML Blockquotes - Mixed Content


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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.