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[(_at_)group=$group]">
<xsl:apply-templates/>
</xsl:for-each>
</p>
to this:
<p num="{(_at_)num}">
<xsl:for-each select="../p[(_at_)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(_at_)hotmail(_dot_)com>
04/27/2005 02:56 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc
Subject
Re: [xsl] 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[(_at_)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>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--