?
Solved

Why do I get the output twice in my pdf from my xml, xslt?

Posted on 2010-01-09
13
Medium Priority
?
191 Views
Last Modified: 2013-11-18
I get my output twice in my pdf file. Look at my pdf.....and my xml code
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
 <xsl:template match="/">
 

 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 
   <fo:layout-master-set>
     <fo:simple-page-master master-name="simple"
                   page-height="29.7cm" 
                   page-width="21cm"
                   margin-top="1cm" 
                   margin-bottom="2cm" 
                   margin-left="2.5cm" 
                   margin-right="2.5cm">
       <fo:region-body margin-top="3cm"/>
       <fo:region-before extent="3cm"/>
       <fo:region-after extent="1.5cm"/>
     </fo:simple-page-master>
   </fo:layout-master-set>
 
 
   <fo:page-sequence master-reference="simple">
   	<fo:flow flow-name="xsl-region-body">
   	       <xsl:apply-templates select="data"/>
   	</fo:flow>
   </fo:page-sequence>

  </fo:root> 
 </xsl:template>
 
 <xsl:template match="data">
       <fo:block>
       	<xsl:apply-templates select="name"/>
        <xsl:apply-templates select="header1"/>
       	<xsl:apply-templates select="section1"/>
        <xsl:apply-templates select="header2"/>
        <xsl:apply-templates select="section2"/>
        
       </fo:block>
 </xsl:template>
 
 <xsl:template match="name">       
       <fo:block font-size="18pt" 
             font-family="sans-serif" 
             line-height="24pt"
             space-after.optimum="15pt"
             background-color="gray"
             color="white"
             text-align="center"
             padding-top="3pt">
         <xsl:value-of select="."/>
       </fo:block> 
 </xsl:template>
 
 <xsl:template match="header1 | header2">
       <fo:block font-size="12pt" 
                 font-family="sans-serif" 
                 line-height="15pt"
                 space-after.optimum="3pt"
                 text-align="justify">
		<xsl:value-of select="."/>
	</fo:block>
</xsl:template>


 <xsl:template match="section1">
       <fo:block font-size="10pt"
                 font-family="sans-serif"
                 line-height="10pt"
                 space-after.optimum="3pt"
                 text-align="justify">
                  <xsl:apply-templates select="para1"/>
                 <xsl:apply-templates select="paraspecial"/>
                 <xsl:apply-templates select="para3"/>
                 <xsl:apply-templates select="para4"/>
                 <xsl:apply-templates select="para5"/>
                 <xsl:apply-templates select="para6"/>
                 <xsl:apply-templates select="para7"/>
                 <xsl:apply-templates select="para8"/>
                 <xsl:apply-templates select="para9"/>
                 <xsl:apply-templates select="para10"/>
                 <xsl:value-of select="."/>
	</fo:block>

</xsl:template>



 <xsl:template match="para1 | para2 | para3 | para4 | para5| para6 | para7 | para8 | para9 | para10">
                    <fo:block font-size="10pt"
                 font-family="sans-serif"
                 line-height="10pt"
                 space-after.optimum="3pt"
                 text-align="justify">
		<xsl:value-of select="."/>
	</fo:block>
</xsl:template>

  <xsl:template match="paraspecial">
       <fo:block font-size="10pt"
             font-family="sans-serif"
             line-height="10pt"
             space-after.optimum="3pt"
             background-color="gray"
             color="white"
             text-align="justify">
         <xsl:value-of select="."/>
       </fo:block>
 </xsl:template>




 <xsl:template match="section2">
       <fo:block font-size="10pt"
                 font-family="sans-serif"
                 line-height="10pt"
                 space-after.optimum="3pt"
                 text-align="justify">
                  <xsl:apply-templates select="para1"/>
                 <xsl:apply-templates select="para2"/>
                 <xsl:apply-templates select="para3"/>
                 <xsl:apply-templates select="para4"/>
                 <xsl:apply-templates select="para5"/>
                 <xsl:apply-templates select="para6"/>
                 <xsl:apply-templates select="para7"/>
                 <xsl:apply-templates select="para8"/>
                 <xsl:apply-templates select="para9"/>
                 <xsl:apply-templates select="para10"/>
                 <xsl:value-of select="."/>
	</fo:block>

</xsl:template>
 
 </xsl:stylesheet>
 

---------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<data>
	<name>
		Inlämning 1
	</name>
        <header1>1.	Inledning</header1>
	<section1>
            <para1>Den första uppgiften i ), XML-teknik, som skall lösas är denna uppgift. Följande var givet för uppgiften:</para1>
            <paraspecial>Instruktioner:</paraspecial>
            <para3>Uppgift 1  Vad är XML?</para3>
            <para4>XML, stylesheet, DocBook, schema, SVG, SGML, HTML, S1000D, editor, verifiering, W3C, DTD, CSS, XSL, XSLT, Arbortext.
                Listan på XML-relaterade begrepp verkar i det närmaste oändlig. Vad betyder de olika begreppen, hur hänger de här begreppen
                ihop, finns det fler intressanta och viktiga begrepp? Vem styr XML och dess utveckling? Vilka aktörer finns är det oberoende
                standardiseringsorgan eller stora programvarutillverkare?</para4>
            <para5>VAD</para5>
            <para6>Din uppgift består av följande delar:</para6>
            <para7>1. Definiera huvudbegrepp inom XML-sfären såsom till exempel stylesheet, DocBook, CSS och W3C. För att få ett grepp om vilka som är viktiga att förstå kan kurslitteraturen samt länkarna i kursmiljön vara till god hjälp.</para7>
            <para8>2. Relatera de olika begreppen till varandra. Finns det begrepp som på något sätt kan sägas vara varianter av något med samma funktion?</para8>
            <para9>3. Vem styr XML och dess utveckling. Beskriv vilka aktörer som finns inom XML-sfären, vilka är det som styr utvecklingen? Vilka effekter kan den här typen av styrning ha?</para9>
            <para10>Syftet med denna övning var att lära sig Vad XML är och alla dess begrepp.</para10>

        </section1>

        <header2>2.	Lösning</header2>
        <section2>
            <para1>1111111111</para1>
            <para2>22222222222</para2>
            <para3>33333333333333333</para3>
            <para4>4444444444444</para4>
            <para5>555555555555</para5>
            <para6>666666666666</para6>
            <para7>66666666666</para7>
            <para8>7777777777777</para8>
            <para9>888888888</para9>
            <para10>9999999999</para10>


        </section2>
</data>

Open in new window

ResultXML2PDF.pdf
0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26274583
simply because you output the data twice

In the templates for section1 and section2 you have a value-of after all the apply-templates
you should remove that line
as an exampe I did it for section1
    <xsl:template match="section1"> 
        <fo:block font-size="10pt" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:apply-templates select="para1"/> 
            <xsl:apply-templates select="paraspecial"/> 
            <xsl:apply-templates select="para3"/> 
            <xsl:apply-templates select="para4"/> 
            <xsl:apply-templates select="para5"/> 
            <xsl:apply-templates select="para6"/> 
            <xsl:apply-templates select="para7"/> 
            <xsl:apply-templates select="para8"/> 
            <xsl:apply-templates select="para9"/> 
            <xsl:apply-templates select="para10"/> 
            <!--<xsl:value-of select="."/> -->
        </fo:block> 

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26274600
I rewrote your stylesheet so it is a bit more readable,
it would be easier to spot errors like this
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/> 
    <xsl:template match="/"> 
        
        
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
            
            <fo:layout-master-set> 
                <fo:simple-page-master master-name="simple" 
                    page-height="29.7cm"  
                    page-width="21cm" 
                    margin-top="1cm"  
                    margin-bottom="2cm"  
                    margin-left="2.5cm"  
                    margin-right="2.5cm"> 
                    <fo:region-body margin-top="3cm"/> 
                    <fo:region-before extent="3cm"/> 
                    <fo:region-after extent="1.5cm"/> 
                </fo:simple-page-master> 
            </fo:layout-master-set> 
            
            
            <fo:page-sequence master-reference="simple"> 
                <fo:flow flow-name="xsl-region-body"> 
                    <xsl:apply-templates select="data"/> 
                </fo:flow> 
            </fo:page-sequence> 
            
        </fo:root>  
    </xsl:template> 
    
    <xsl:template match="data"> 
        <fo:block> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="name">        
        <fo:block font-size="18pt"  
            font-family="sans-serif"  
            line-height="24pt" 
            space-after.optimum="15pt" 
            background-color="gray" 
            color="white" 
            text-align="center" 
            padding-top="3pt"> 
            <xsl:value-of select="."/> 
        </fo:block>  
    </xsl:template> 
    
    <xsl:template match="header1 | header2"> 
        <fo:block font-size="12pt"  
            font-family="sans-serif"  
            line-height="15pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    
    <xsl:template match="section1"> 
        <fo:block font-size="10pt" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
        
    </xsl:template> 
    
    <xsl:template match="*[translate(name(), '0123456789', '') = 'para']"> 
        <fo:block font-size="10pt" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="paraspecial"> 
        <fo:block font-size="10pt" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            background-color="gray" 
            color="white" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="section2"> 
        <fo:block font-size="10pt" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
        
    </xsl:template> 
    
</xsl:stylesheet> 

Open in new window

0
 

Author Comment

by:Mickeys
ID: 26275224
I think your template looks just fine. I just have one question. If I use that how the heck do I get newline (enter) into my pdf?

I have tried and tried but I wont get it to work. I want it to be output just like I write a word document

Header

Underheader
text text text text text text text text text text text text text text text text text text .text text text text text text text text text .text text text text text text text text text .text text text text text text text text text

text text text text text text text text text text text text text text text .text text text text text text text text text text text text text text text text text text text text text .

text text text text text text text text text text text text . text text text text text text text text text

Under header

text text text text text text text text text text text text text text text . text text text text text text text text text .text text text text text text text text text text text text

text text text text text text text text text text text text ..text text text text text text text text text text text text .text text text text text text .
0
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26275313
well, my new stylesheet did not change anything but less complex syntax.
The newlines are in the fo:block, and those are still there
I am off to bed now, I will check what goes wrong tomorrow morning
0
 

Author Comment

by:Mickeys
ID: 26276559
Well I tried your xsl and it looks much easier to read and seems to be alot better. :-)

But look at my pdf. I would like to have newlines. How do I managed that? Right now the text just comes after each other.

I cant fiugre it out
ResultXML2PDF.pdf
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26276603
Let me guess by the way. Swedisch?
God morgon!

I must say that I don't understand the problem. The fo:block introduces a new blockelement in your output,
forcing it to start on a new line. You do that for each construct. So I am not sure what you want. I see "hard returns" in teh PDF you send.
Do you want more spacing?
Or do you want to reproduce the newlines, as they are in para4? That will be a bit tricky, cause you also have too much spaces there.
Can you be a bit more specific of what exactly you need?
0
 

Author Comment

by:Mickeys
ID: 26276821
hehe Ja svensk. :-)

Yes the problem is that between the sections I would like to have a new line. So if it looks like this now


1. Inledning
Den första uppgiften i ), XML-teknik, som skall lösas är denna uppgift. Följande var givet för uppgiften:
Instruktioner:
Uppgift 1  Vad är XML?
XML, stylesheet, DocBook, schema, SVG, SGML, HTML, S1000D, editor, verifiering, W3C, DTD, CSS,
XSL, XSLT, Arbortext. Listan på XML-relaterade begrepp verkar i det närmaste oändlig. Vad betyder
de olika begreppen, hur hänger de här begreppen ihop, finns det fler intressanta och viktiga begrepp?
Vem styr XML och dess utveckling? Vilka aktörer finns är det oberoende standardiseringsorgan eller
stora programvarutillverkare?
VAD
Din uppgift består av följande delar:


I would like it to look like this

1. Inledning

Den första uppgiften i ), XML-teknik, som skall lösas är denna uppgift. Följande var givet för uppgiften:

Instruktioner:

Uppgift 1  Vad är XML?
XML, stylesheet, DocBook, schema, SVG, SGML, HTML, S1000D, editor, verifiering, W3C, DTD, CSS,
XSL, XSLT, Arbortext. Listan på XML-relaterade begrepp verkar i det närmaste oändlig. Vad betyder
de olika begreppen, hur hänger de här begreppen ihop, finns det fler intressanta och viktiga begrepp?
Vem styr XML och dess utveckling? Vilka aktörer finns är det oberoende standardiseringsorgan eller
stora programvarutillverkare?

VAD
Din uppgift består av följande delar:
.......
0
 

Author Comment

by:Mickeys
ID: 26276829
asch......copy paste error.

Here you go again



Instruktioner:

Uppgift 1

Vad är XML?
XML, stylesheet, DocBook, schema, SVG, SGML, HTML, S1000D, editor, verifiering, W3C, DTD, CSS,
XSL, XSLT, Arbortext. Listan på XML-relaterade begrepp verkar i det närmaste oändlig. Vad betyder
de olika begreppen, hur hänger de här begreppen ihop, finns det fler intressanta och viktiga begrepp?
Vem styr XML och dess utveckling? Vilka aktörer finns är det oberoende standardiseringsorgan eller
stora programvarutillverkare?

VAD
Din uppgift består av följande delar:


I would like it to look like this

1. Inledning

Den första uppgiften i ), XML-teknik, som skall lösas är denna uppgift. Följande var givet för uppgiften:

Instruktioner:

Uppgift 1

Vad är XML?

XML, stylesheet, DocBook, schema, SVG, SGML, HTML, S1000D, editor, verifiering, W3C, DTD, CSS,
XSL, XSLT, Arbortext. Listan på XML-relaterade begrepp verkar i det närmaste oändlig. Vad betyder
de olika begreppen, hur hänger de här begreppen ihop, finns det fler intressanta och viktiga begrepp?
Vem styr XML och dess utveckling? Vilka aktörer finns är det oberoende standardiseringsorgan eller
stora programvarutillverkare?

VAD
Din uppgift består av följande delar:
.......
0
 

Author Comment

by:Mickeys
ID: 26276836
by the way. I do have one question but I think it is better if you e-mail me.
nero2000 at hotmai dot com
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26277502
Oh, what you need is space-before attribute in each block
eg. <fo:block space-before="5mm"

Here is the XSLT, changed for that, you might want to play with the size a bit
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 26277507
and now with XSLT
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/> 
    <xsl:template match="/"> 
        
        
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
            
            <fo:layout-master-set> 
                <fo:simple-page-master master-name="simple" 
                    page-height="29.7cm"  
                    page-width="21cm" 
                    margin-top="1cm"  
                    margin-bottom="2cm"  
                    margin-left="2.5cm"  
                    margin-right="2.5cm"> 
                    <fo:region-body margin-top="3cm"/> 
                    <fo:region-before extent="3cm"/> 
                    <fo:region-after extent="1.5cm"/> 
                </fo:simple-page-master> 
            </fo:layout-master-set> 
            
            
            <fo:page-sequence master-reference="simple"> 
                <fo:flow flow-name="xsl-region-body"> 
                    <xsl:apply-templates select="data"/> 
                </fo:flow> 
            </fo:page-sequence> 
            
        </fo:root>  
    </xsl:template> 
    
    <xsl:template match="data"> 
        <fo:block> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="name">        
        <fo:block font-size="18pt"  
            space-before="5mm" 
            font-family="sans-serif"  
            line-height="24pt" 
            space-after.optimum="15pt" 
            background-color="gray" 
            color="white" 
            text-align="center" 
            padding-top="3pt"> 
            <xsl:value-of select="."/> 
        </fo:block>  
    </xsl:template> 
    
    <xsl:template match="header1 | header2"> 
        <fo:block font-size="12pt"  
            space-before="5mm" 
            font-family="sans-serif"  
            line-height="15pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    
    <xsl:template match="section1"> 
        <fo:block font-size="10pt" 
            space-before="5mm" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
        
    </xsl:template> 
    
    <xsl:template match="*[translate(name(), '0123456789', '') = 'para']"> 
        <fo:block font-size="10pt" 
            space-before="5mm" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="paraspecial"> 
        <fo:block font-size="10pt" 
            space-before="5mm" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            background-color="gray" 
            color="white" 
            text-align="justify"> 
            <xsl:value-of select="."/> 
        </fo:block> 
    </xsl:template> 
    
    <xsl:template match="section2"> 
        <fo:block font-size="10pt" 
            space-before="5mm" 
            font-family="sans-serif" 
            line-height="10pt" 
            space-after.optimum="3pt" 
            text-align="justify"> 
            <xsl:apply-templates select="*"/> 
        </fo:block> 
        
    </xsl:template> 
    
</xsl:stylesheet> 

Open in new window

0
 

Author Closing Comment

by:Mickeys
ID: 31674992
This was exactlly what I was after. Are gonna open a new thread with other questions on this. Hope to see you there!!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26277627
welcome
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question