By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,025 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,025 IT Pros & Developers. It's quick & easy.

convert xml to pdf

P: n/a
I want to convert this xml to pdf using cocoon

<?xml version="1.0" encoding="ISO-8859-1" ?>
<document>
<header>
<title>Pagina</title>
</header>
<body>
<h1>Link dei siti pił visitati da me</h1>
<ul>
<li>
<link href="http://****">***</link>
</li>
<li>
<link href="http://***">***</link>
</li>
<li>
<link href="http://***">***</link>
</li>
<li>
<link href="http://***">***</link>
</li>
</ul>
</body>
</document>
The xsl I wrote to convert is this
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="page"
page-height="29.7cm"
page-width="21cm"
margin-top="1cm"
margin-bottom="2cm"
margin-left="2.5cm"
margin-right="2.5cm">
<fo:region-before extent="3cm"/>
<fo:region-body margin-top="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>

<fo:page-sequence-master master-name="all">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page"
page-position="first"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="all">
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="center"
font-size="10pt"
font-family="serif"
line-height="14pt">page <fo:page-number/></fo:block>
</fo:static-content>

<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template match="title">
<fo:block font-size="36pt" space-before.optimum="24pt"
text-align="center"><xsl:apply-templates/></fo:block>
</xsl:template>

<xsl:template match="link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

The problem is that the pdf shows only the title and the part of the
body is not visible.
What I need to change to make visible the body in the pdf??
Please I ask for help!!!

Apr 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jorge said the following on 07-04-2006 11:54 +0200:
I want to convert this xml to pdf using cocoon
I have no experience with cocoon, but I don't think that really matters,
it's about your XSL file.

[XML file snipped] The xsl I wrote to convert is this

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="page"
page-height="29.7cm"
page-width="21cm"
margin-top="1cm"
margin-bottom="2cm"
margin-left="2.5cm"
margin-right="2.5cm">
<fo:region-before extent="3cm"/>
<fo:region-body margin-top="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>

<fo:page-sequence-master master-name="all">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page"
page-position="first"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="all">
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="center"
font-size="10pt"
font-family="serif"
line-height="14pt">page <fo:page-number/></fo:block>
</fo:static-content>

<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template match="title">
<fo:block font-size="36pt" space-before.optimum="24pt"
text-align="center"><xsl:apply-templates/></fo:block>
</xsl:template>

<xsl:template match="link">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
This is not in a fo:block or fo:inline element. When you look at the
result FO file (which is itself an XML file), you see that href's are
just "laying around"; they don't have any fo element associated with
them, other than only the <fo:flow flow-name="xsl-region-body">

But an fo:flow element should have 0 or more bl
The problem is that the pdf shows only the title and the part of the
body is not visible.
What I need to change to make visible the body in the pdf??
Please I ask for help!!!


Only the title and page number are in a fo:block element. AFAIK the
whole page should be a fo:block element (which can of course contain
other fo:block and fo:inline elements, but the page itself is a block),
or should be multiple blocks stacked together.

I think putting a block in "xsl-region-body" will fix it, something like
this:

<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:flow>

Or put a fo:block element where the first matching template begins.

Normally I put it on the element which matches my XML root element en
put there all the default styles, so all children will inheret those values.

But you should also wrap those href's in an fo:inline element.

--
Regards
Harrie
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.