You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Ashish Kulkarni <as...@gmail.com> on 2011/02/09 06:26:53 UTC

XML data with HTML tags, and creating PDF file

Hi
I have an XML document as below, i am using FOP to create PDF file, i am
hoping to translate those HTML tags in my output, for example i want some
text bold in my PDF file, so if the XML file has

<para4>
     My Data, this i want italic
       <![CDATA[this is my node. <i>this is italics</i> this is
<b>bold</b>]]>
    </para4>
and in style sheet i have

<fo:block text-align="left" >
<xsl:value-of select="para4" disable-output-escaping="no" ></xsl:value-of>
</fo:block>

But this just creates PDF file with all the text, it does not make text
italic or bold, the output in PDF file is the whole data as below

My Data, this i want italic
       <![CDATA[this is my node. <i>this is italics</i> this is
<b>bold</b>]]>
-- 
Ashish
www.ayurwellness.com
www.mysoftwareneeds.com

Re: XML data with HTML tags, and creating PDF file

Posted by Andreas Delmelle <an...@telenet.be>.
On 09 Feb 2011, at 06:26, Ashish Kulkarni wrote:

Hi

This is actually strictly an XSLT-related question. This list is dedicated to questions about FOP usage (= converting FO to another output format using FOP). Please try to keep that in mind for future posts. Thanks!

Now that that's out of the way:

> I have an XML document as below, i am using FOP to create PDF file, i am hoping to translate those HTML tags in my output, for example i want some text bold in my PDF file, so if the XML file has
> 
> <para4>
>      My Data, this i want italic
>        <![CDATA[this is my node. <i>this is italics</i> this is <b>bold</b>]]>
>     </para4>
> and in style sheet i have
> 
> <fo:block text-align="left" >
>   <xsl:value-of select="para4" disable-output-escaping="no" ></xsl:value-of>
> </fo:block>

That (disable-output-escaping) is best not used. It is deprecated in XSLT 2.0, and in XSLT 1.0, strictly speaking, processors are not mandated to support this.

Besides that, using the above construct will yield FO with intermingled HTML markup like:

<fo:block>this is my node. <i>this is italics</i> this is <b>bold</b></fo:block>

FOP is not designed to interpret HTML, only the FO part. In your case, the processor supports d-o-e, so the 'i' and 'b' elements are reported by the parser, but FOP does not know what to do with them, so just handles the text.

In order to convert that to proper FO (= markup that FOP knows how to interpret):
1. First, you will need to make sure the <![CDATA[...]]> markup in the source file is eliminated, so that you just get plain XHTML markup. I.e. you do *not* want the lexical equivalent of

...this is my node. &lt;i>this is italics&lt;/i> this is &lt;b>bold&lt;/b>...

You need the 'i' and 'b' elements to be reported to the XSLT processor as elements.

2. Once that is done, you can write simple XSLT templates to translate the XHTML markup to FO markup, like so:

<xsl:template match="i">
  <fo:wrapper font-style="italic"><xsl:value-of select="." /></fo:wrapper>
</xsl:template>

and further on, when building the fo:block, using apply-templates will trigger the built-in template rule for the text() nodes, and the use of the above template to handle the 'i' element node:

<fo:block><xsl:apply-templates select="para4" /></fo:block>



Regards,

Andreas
---


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org