Dear all,

I am new in XMl and XSL, I want to produce PDF output from XML and XSL using
FOP. I tried to compile source code (Shakespearean Sonnet) that i found in :
http://www-106.ibm.com/developerworks/education/transforming-xml/xmltopdf/in
dex.html

here are the result when i tried to compile :
i attached xml, dtd and xsl source code  ---
Please i need your advise ....

Terima kasih,
Ali
==================================================================
[DEBUG]: Input mode:
[DEBUG]: xslt transformation
[DEBUG]: xml input file: c:\ali\sonnet\xmlsonnet.xml
[DEBUG]: xslt stylesheet: c:\ali\sonnet\xslsonnet.xsl
[DEBUG]: Output mode:
[DEBUG]: pdf
[DEBUG]: output file: c:\ali\alis2.pdf
[DEBUG]: OPTIONS
[DEBUG]: no user configuration file is used [default]
[DEBUG]: debug mode on
[DEBUG]: dump configuration
[DEBUG]: quiet mode on
[DEBUG]: base directory: file:/c:/ali/sonnet/
[INFO]: FOP 0.20.3
[DEBUG]: using SAX parser org.apache.xerces.parsers.SAXParser
[INFO]: building formatting object tree
[DEBUG]: setting up fonts
[ERROR]:
org.apache.fop.apps.FOPException:
        at org.apache.fop.apps.Driver.render(Driver.java:486)
        at
org.apache.fop.apps.CommandLineStarter.run(CommandLineStarter.java:72)
        at org.apache.fop.apps.Fop.main(Fop.java:19)

---------

javax.xml.transform.TransformerException:
        at
org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:137)
        at org.apache.fop.apps.Driver.render(Driver.java:481)
        at
org.apache.fop.apps.CommandLineStarter.run(CommandLineStarter.java:72)
        at org.apache.fop.apps.Fop.main(Fop.java:19)

---------

javax.xml.transform.TransformerException:
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava, Compiled Code)
        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
        at java.lang.Thread.run(Unknown Source)
---------
java.lang.NullPointerException:
        at org.apache.fop.fo.flow.Flow.setFlowName(Flow.java:98)
        at org.apache.fop.fo.flow.Flow.<init>(Flow.java:77)
        at org.apache.fop.fo.flow.Flow$Maker.make(Flow.java:28)
        at
org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:261)
        at
org.apache.xalan.transformer.QueuedStartElement.flush(QueuedStartElement.jav
a:286)
        at
org.apache.xalan.transformer.ResultTreeHandler.flushPending(ResultTreeHandle
r.java:774)
        at
org.apache.xalan.transformer.ResultTreeHandler.endElement(ResultTreeHandler.
java:283)
        at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java,
Compiled Code)
        at
org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.ja
va, Compiled Code)
        at
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
a:193)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java, Compiled Code)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2097)
        at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
Impl.java:2029)
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava, Compiled Code)
        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
        at java.lang.Thread.run(Unknown Source)

C:\Rsearch\bin\fop-0.20.3>

===========================================
<?xml version="1.0"?>

<!DOCTYPE sonnet SYSTEM "sonnet.dtd">
<root type="Shakespearean">
  <author>
    <last-name>Shakespeare</last-name>
    <first-name>William</first-name>
    <nationality>British</nationality>
    <year-of-birth>1564</year-of-birth>
    <year-of-death>1616</year-of-death>
  </author>
  <title>Sonnet 130</title>
  <lines>
    <line>My mistress' eyes are nothing like the sun,</line>
    <line>Coral is far more red than her lips red.</line>
    <line>If snow be white, why then her breasts are dun,</line>
    <line>If hairs be wires, black wires grow on her head.</line>
    <line>I have seen roses damasked, red and white,</line>
    <line>But no such roses see I in her cheeks.</line>
    <line>And in some perfumes is there more delight</line>
    <line>Than in the breath that from my mistress reeks.</line>
    <line>I love to hear her speak, yet well I know</line>
    <line>That music hath a far more pleasing sound.</line>
    <line>I grant I never saw a goddess go,</line>
    <line>My mistress when she walks, treads on the ground.</line>
    <line>And yet, by Heaven, I think my love as rare</line>
    <line>As any she belied with false compare.</line>
  </lines>
</root>

Attachment: sonnet.dtd
Description: Binary data

<!-- 
A Shakespearean sonnet : 
1. Define stylesheet header
2. define page lay out
3. write title
4. write info abt author
5. create table to hold all the sonnet 
6. processing all the lines using color scheme	
-->

<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
     xmlns:fo="http://www.w3.org/1999/XSL/Format";>
     
		<!--1. Define StyleSheet header-->
		<xsl:template match="/">
			<xsl:apply-templates select="root"/>
		</xsl:template>


		<xsl:template match ="root">
			<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>	
				<!--2. Define LayOut-->
				<fo:layout-master-set>
					<fo:simple-page-master
							master-name="simple"
							margin-top="75pt"
							margin-bottom="75pt"
							margin-left="75pt"
							margin-right="75pt">
							<fo:region-body margin-bottom="75pt"/>					
					</fo:simple-page-master>
				</fo:layout-master-set>
		
				<fo:page-sequence >
					<!--3. Tittle-->	
					<fo:flow>
						<xsl:apply-templates select="title"/>
						<xsl:apply-templates select="author"/>	
					</fo:flow>
				</fo:page-sequence>
		  </fo:root>
		</xsl:template>

		
		<xsl:template match="title">
			<fo:block
				font-size="24pt"
				line-height="27pt"
				text-align-last="start"
				space-before.optimum="24pt">
			</fo:block>				
		</xsl:template>

		<xsl:template match="author">
			<fo:block
				font-size="12pt"
				line-height="15pt"
				text-align-last="start"
				space-before.optimum="12pt">
				<xsl:text>Author:</xsl:text>
				<xsl:apply-templates select="first-name"/>
				<xsl:text></xsl:text>
				<xsl:apply-templates select="last-name"/>
				<xsl:text></xsl:text>
	      <fo:wrapper font-style="italic">
	        <xsl:apply-templates select="nationality"/>
	        <xsl:text>, </xsl:text>
	        <xsl:apply-templates select="year-of-birth"/>
	        <xsl:text>-</xsl:text>
	        <xsl:apply-templates select="year-of-death"/>
	      </fo:wrapper>
	      <xsl:text>)</xsl:text>
    	</fo:block>
    </xsl:template>
  
  
	<!--4. Table-->	
  <fo:table space-before.optimum="6pt">
            <fo:table-column column-width="30pt"/>
            <fo:table-column column-width="450pt"/>   
            <fo:table-body>
              <xsl:apply-templates select="lines/line"/>	
            </fo:table-body>
	</fo:table>                            
	<!--5. Process all lines-->	                                 
  <xsl:template match="line[1]|line[3]">
    <fo:table-row space-before.optimum="3pt">
      <fo:table-cell>
        <fo:block font-size="14pt" color="gray">A</fo:block>
      </fo:table-cell>
      <fo:table-cell>
        <fo:block color="green"><xsl:value-of select="."/></fo:block>
      </fo:table-cell>
     </fo:table-row>
   </xsl:template>
     
</xsl:stylesheet>              

Reply via email to