Link to home
Start Free TrialLog in
Avatar of Mickeys
MickeysFlag for Sweden

asked on

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

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
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

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

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

Avatar of Mickeys

ASKER

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 .
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
Avatar of Mickeys

ASKER

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
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?
Avatar of Mickeys

ASKER

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:
.......
Avatar of Mickeys

ASKER

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:
.......
Avatar of Mickeys

ASKER

by the way. I do have one question but I think it is better if you e-mail me.
nero2000 at hotmai dot com
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
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mickeys

ASKER

This was exactlly what I was after. Are gonna open a new thread with other questions on this. Hope to see you there!!