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

Re: blockQuotes to blockQuote p p

Subject: Re: blockQuotes to blockQuote p p
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 01 May 2003 17:23:15 -0400
blockquote bullet
Jim,

A couple of years ago at the Extreme conference I had the honor of hanging out with Mike Kay, who told us about features slated for XSLT 2.0 and challenged us with a few "advanced" XSLT problems.

One of them is effectively yours. The source:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- from Hart's Rules for Compositors, 39th edition, OUP -->
<rules>
<p>The following should appear in italic:</p>
<bullet>Titles of operas, ballets, song cycles, symphonic poems,
  oratorios, overtures.</bullet>
<bullet>Abbreviated volume indications: <i>pp</i>, <i>mf</i>, etc.
  (these are always lower case).</bullet>
<p>The following should appear in roman, with single quotation marks:</p>
<bullet>Titles of single songs</bullet>
<bullet>Popular names of works, e.g. the 'Jupiter' Symphony</bullet>
<bullet>Phrases denoting tempo marks (unless used as the name of
a movement): 'allegro non troppo', 'più tranquillo'.</bullet>
<p>The following should appear in roman without quotation marks:</p>
<bullet>Musically descriptive titles: Piano Sonata Op. 111, Finale.</bullet>
<bullet>Technical terms and names of instruments: andante, cor anglais,
forte, organum, sh&#x0113;ng, vihuela.</bullet>
</rules>

The problem: convert to HTML, grouping adjacent <bullet> nodes as <li> elements inside <ul> wrappers. (See it's the same, isn't it.)

There are actually at least two solutions that are fairly straightforward. One is a grouping solution (key the bullets to the first preceding sibling bullet whose immediate preceding element isn't a bullet; let those bullets pick up the others). The other is a forward-walking solution, like what you're trying. This is my version of that solution to Mike's problem:

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

<xsl:output method="html" encoding="iso-8859-1"/>

<xsl:template match="rules">
  <div>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="p">
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="bullet">
  <xsl:if test="not(preceding-sibling::*[1][self::bullet])">
    <ul>
      <li><xsl:apply-templates/></li>
      <xsl:apply-templates mode="in-list"
        select="following-sibling::*[1][self::bullet]" />
    </ul>
  </xsl:if>
</xsl:template>

<xsl:template match="bullet" mode="in-list">
  <li><xsl:apply-templates/></li>
  <xsl:apply-templates mode="in-list"
    select="following-sibling::*[1][self::bullet]"/>
</xsl:template>

</xsl:stylesheet>

I think you'll see it's basically what you're trying to do, only cleaned up and using a mode instead of named templates.

The output (just to show it runs):

<div>
   <p>The following should appear in italic:</p>
   <ul>
      <li>Titles of operas, ballets, song cycles, symphonic poems,
           oratorios, overtures.
      </li>
      <li>Abbreviated volume indications: pp, mf, etc.
           (these are always lower case).
      </li>
   </ul>
   <p>The following should appear in roman, with single quotation marks:</p>
   <ul>
      <li>Titles of single songs</li>
      <li>Popular names of works, e.g. the 'Jupiter' Symphony</li>
      <li>Phrases denoting tempo marks (unless used as the name of
         a movement): 'allegro non troppo', 'pi&ugrave; tranquillo'.
      </li>
   </ul>
   <p>The following should appear in roman without quotation marks:</p>
   <ul>
      <li>Musically descriptive titles: Piano Sonata Op. 111, Finale.</li>
      <li>Technical terms and names of instruments: andante, cor anglais,
         forte, organum, sh&#275;ng, vihuela.
      </li>
   </ul>
</div>

I hope it helps,
Wendell

At 03:47 PM 5/1/2003, you wrote:
<section>
        <head></head>
        <parallelPassage></parallelPassage>
        <paragraph></paragraph>
        <blockQuotes></blockQuotes>
        <blockQuotes></blockQuotes>
        <blockQuotes></blockQuotes>
        <paragraph></paragraph>
        <paragraph></paragraph>
        <blockQuotes></blockQuotes>
        <blockQuotes></blockQuotes>
        <blockQuotes></blockQuotes>
        <paragraph></paragraph>
</section>

output should be:

<div>
        <head></head>
        <parallelPassage></parallelPassage>
        <p></p>
        <blockQuote>
                <p></p>
                <p></p>
                <p></p>
        </blockQuote>
        <p></p>
        <p></p>
        <blockQuote>
                <p></p>
                <p></p>
                <p></p>
        </blockQuote>
        <p></p>
</div>


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
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
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.