[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: JBryant@xxxxxxxxx
Date: Wed, 27 Apr 2005 15:22:40 -0500
xsl for each mixed
Hi, Edward,

In a nutshell, p[not(preceding-sibling::*[1]/self::p)] says, "the p whose 
first preceding sibling is not a p". I used it to find the start of each 
group of paragraphs that should be grouped together.

You can get the num value into the resulting p blocks by changing this 
section:

    <p>
      <xsl:for-each select="../p[@group=$group]">
        <xsl:apply-templates/>
      </xsl:for-each>
    </p>

to this:

    <p num="{@num}">
      <xsl:for-each select="../p[@group=$group]">
        <xsl:apply-templates/>
      </xsl:for-each>
    </p>

I apologize for the oversight. In tangling with the grouping problem I 
forgot that you needed the num attribute to come through.

In a larger stylesheet meant to solve real problems (rather than the tiny 
snippet we have here), you could insert the method of handling blockquotes 
into a choose statement:

<xsl:template match="p">
  <xsl:choose>
    <xsl:when test="blockquote">
      <!-- Process the paragraph to handle the blockquote -->
    </xsl:when>
    <xsl:otherwise>
      <!-- Process the paragraph the usual, more simple, way -->
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

However, You'll still be checking each paragraph for the presence of a 
blockquote. However, any tool must do the same, yes? If any paragraph can 
contain a blockquote, doesn't the processing tool have to check every 
paragraph for the presence of a blockquote? So, some problems require this 
kind of processing. Of course, you could change the XML source to not have 
the root problem, but I assumed that was out of bounds.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





"Edward Bryant" <bryant_edward@xxxxxxxxxxx> 
04/27/2005 02:56 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
Re:  Transforming XML Blockquotes - Mixed Content - XSLT 1.0 Solution






Hello again,

Reply to David Carlisle and Wendell:

To the comments that I might try to use divs instead of the standard XHTML 

blockquote tag (because XHTML allows nested divs), I tried it and it 
doesn't 
work. If I remember correctly nested divs technically work but in IE6 a 
paragraph's initial indent is re-applied to the text following a 
blockquote 
(so, the continued part of the paragraph falsely appears to be a new 
paragraph). Hence, while some style features, such as line-height inherit 
correctly to the post blockquote text, it also incorrectly inherits the 
paragraph's initial indent.

Reply to David Carlisle and Michael Kay:

Thanks for David's explanation of why not to use DOE, as well as the 
tree-based reasoning behind XSLT (I understand why this kind of thing is a 

problem better). On the responses to my comment that Jay's solution was 
"overly complex", I did not mean that the offered solution was complex in 
that there were too many lines of code. What I meant was that the solution 

ends up handling or touching on a lot of data that isn't even involved in 
the blockquote problem. It is complex in that it results in a lot of extra 

processing of data, as in the example of a 20 page document with only one 
blockquote in one paragraph or the processing of documents without any 
blockquotes, etc.

Reply to Jay Bryant:

Thanks for your patience and your posting of a 1.0 compliant version of 
your 
solution. I did, however, have a few questions:

1. I tried to decipher this XPATH expression but I can't seem to 
understand 
it, can someone help explain what this is doing

         p[not(preceding-sibling::*[1]/self::p)]

2. In the below stylesheet (the second of the two you offered), how do you 

differentiate between the p representing the initial paragraph and the 
continued paragraph p tags. I need to figure out a way to output the 
original paragraph's "num" attribute next to the start of each real 
paragraph (but not repeat it for the new p tags surrounding the continued 
paragraph text).

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

  <xsl:template match="x">
  <html>
  <head>
  <title>Paragraph Chunking Test</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <xsl:for-each select="p[not(preceding-sibling::*[1]/self::p)]">
    <xsl:variable name="group" select="@group"/>
    <p>
      <xsl:for-each select="../p[@group=$group]">
        <xsl:apply-templates/>
      </xsl:for-each>
    </p>
    <xsl:apply-templates select="following-sibling::blockquote"/>
    </xsl:for-each>
  </body>
  </html>
  </xsl:template>

  <xsl:template match="p"/>

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

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

</xsl:stylesheet>

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.