Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2010-01-09
13
Medium Priority
?
193 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

580 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