This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Formatting bold and italics within a paragraph
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Formatting bold and italics within a paragraph
- From: "Corey Spitzer" <cspitzer at cisco dot com>
- Date: Thu, 23 Aug 2001 15:46:44 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
do this:
<xsl:template match="p">
<fo:block><xsl:apply-templates/></fo:block>
</xsl:template>
<xsl:template match="i">
<fo:inline font-style="italic" font-size
="20pt"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="b">
<fo:inline font-style="bold" font-size
="20pt"><xsl:apply-templates/></fo:inline>
</xsl:template>
-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Gagan Bhalla
Sent: Thursday, August 23, 2001 3:38 PM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] Formatting bold and italics within a paragraph
Hello,
I am trying to write a stylesheet that converts paragraphs into fo:blocks
and while doing so, it retains the formatting inside the para, for example
the bold and italic tags embedded inside the <p> and </p> tags? How do I get
text embedded within a pargraph to get recognized and output in the order it
is encountered?
For example, If I have XML like :
<html xml:lang="en" lang="en">
<body>
<p>This is normal text. This is<b>something in bold </b>Text after bold.
This is <i>In Italics.</i> Text after Italics.</p>
</body>
</html>
Currently, I have a template in my stylesheet that tries to detect the child
tags, <b> and <i> once it reaches a para and output them inline. But it
does'nt get me the text that is within the para but outside the embedded
tags. For example, the output of the above XML upon running thru the XSL
given is missing the "Text after bold. This is" and "Text after Italics." in
it's output.
<fo:block>This is normal text. This is<fo:inline font-style="bold" font-size
="20pt" > something in bold </fo:inline><fo:inline font-style="italic"
font-size ="20pt" > In Italics.</fo:inline><fo:inline font-style="normal"
font-size ="10pt" > This is normal text. This is</fo:inline></fo:block>
Thanks,
Gagan
The stylesheet code fragment looks like this:
<xsl:template match="html/body/p">
<xsl:text disable-output-escaping="yes"><fo:block></xsl:text>
<xsl:value-of select="text()" />
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="name()='b'">
<!-- this creates a FO with bold tag -->
<xsl:text disable-output-escaping="yes"><fo:inline
font-style="bold" font-size ="20pt" ></xsl:text><xsl:text>
</xsl:text><xsl:value-of select="." />
<xsl:text
disable-output-escaping="yes"></fo:inline></xsl:text>
</xsl:when>
<xsl:when test="name()='i'">
<!-- this creates a FO with italicized text -->
<xsl:text disable-output-escaping="yes"><fo:inline
font-style="italic" font-size ="20pt" ></xsl:text> <xsl:text>
</xsl:text><xsl:value-of select="." />
<xsl:text
disable-output-escaping="yes"></fo:inline></xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- this creates a FO with normal text -->
<xsl:text disable-output-escaping="yes"><fo:inline
font-style="normal" font-size ="10pt" ></xsl:text> <xsl:text>
</xsl:text><xsl:value-of select="." />
<xsl:text
disable-output-escaping="yes"></fo:inline></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- remainder of the para after reading all embedded tags -->
<xsl:text disable-output-escaping="yes"><fo:inline font-style="normal"
font-size ="10pt" ></xsl:text><xsl:text> </xsl:text><xsl:value-of
select="text()" /><xsl:text
disable-output-escaping="yes"></fo:inline></xsl:text>
<xsl:text disable-output-escaping="yes"></fo:block></xsl:text>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list