2013-07-09 4 views
2

내가 XML 데이터와 XSL 스타일 시트를 사용하여 PDF를 만들 수 아파치 FOP를 사용하려고하지만 다음과 같은 오류를아파치 FOP

org.apache.fop.apps가 계속하여 PDF를 생성 할 수 없습니다. FOPException : org.apache.fop.fo.ValidationException : "{http://www.w3.org/1999/XSL/Format} 블록"이 (가) "fo : root"의 유효한 하위 요소가 아닙니다! (컨텍스트 정보가 없습니다) javax.xml.transform.TransformerException : org.apache.fop.fo.ValidationException : "{http://www.w3.org/1999/XSL/Format} 블록"이 (가) "fo : root"의 유효한 하위 요소가 아닙니다! (문맥 정보가 없음)

이상한 점은 로컬 Windows 컴퓨터에서 테스트했을 때 이상하게 작동하지만 데비안 서버에서 동일한 작업을 시도했을 때이 오류가 발생했습니다. 에 내가 확인 한 XSLT 프로세스 :

<?xml version="1.0" encoding="UTF-8"?> 
<report> 
    <heading>Heading</heading> 
    <mailersent>18/06/2013 14:23</mailersent> 
    <reportgenerated>18/06/2013 17:26</reportgenerated> 
    <portrait> 
     <title>Summary</title> 
     <graph>graphs/graph1.png</graph> 
     <stats> 
      <stat> 
       <value>16.67%</value> 
       <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text> 
      </stat> 
      <stat> 
       <value>2.25%</value> 
       <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text> 
      </stat> 
      <stat> 
       <value>13.49%</value> 
       <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor through</text> 
      </stat> 
      <stat> 
       <value>8.99%</value> 
       <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text> 
      </stat> 
     </stats> 
     </portrait> 
</report> 

스타일 시트 :

<?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" indent="yes"/> 

<xsl:template match="node()|@*"> 
    <xsl:apply-templates select="node()|@*"/> 
</xsl:template> 

<xsl:template match="/report"> 
    <fo:root> 
     <fo:layout-master-set> 
      <fo:simple-page-master master-name="portraitLayout" page-height="29.7cm" page-width="21.0cm" margin="1cm"> 
       <fo:region-body margin-bottom="1cm"/> 
       <fo:region-after extent="1cm"/> 
      </fo:simple-page-master> 
      <fo:simple-page-master master-name="landscapeLayout" page-height="21cm" page-width="30cm" margin="1cm"> 
       <fo:region-body margin-bottom="1cm"/> 
       <fo:region-after extent="1cm"/> 
      </fo:simple-page-master> 
     </fo:layout-master-set> 

     <fo:page-sequence master-reference="portraitLayout"> 
      <fo:flow flow-name="xsl-region-body"> 
       <xsl:call-template name="heading"/> 
      </fo:flow> 
     </fo:page-sequence> 

     <fo:page-sequence master-reference="portraitLayout"> 
      <fo:flow flow-name="xsl-region-body"> 
       <xsl:call-template name="genTOC"/> 
      </fo:flow> 
     </fo:page-sequence> 
     <xsl:apply-templates/> 
    </fo:root> 
</xsl:template> 

<xsl:template name="genTOC"> 
    <fo:block break-before='page'> 
     <fo:block margin-bottom="1cm" font-size="16pt" font-weight="bold" text-align="center">Contents</fo:block> 
     <xsl:for-each select="//portrait|//landscape"> 
      <fo:block text-align-last="justify"> 
       <fo:basic-link internal-destination="{generate-id(.)}"> 
        <xsl:value-of select="title" /> 
        <fo:leader leader-pattern="dots" /> 
        <fo:page-number-citation ref-id="{generate-id(.)}" /> 
       </fo:basic-link> 
      </fo:block> 
     </xsl:for-each> 
    </fo:block> 
</xsl:template> 

<xsl:template match="portrait"> 
    <fo:page-sequence master-reference="portraitLayout" id="{generate-id(.)}"> 
     <fo:static-content flow-name="xsl-region-after"> 
      <fo:block font-size="8pt" text-align="center" border-top-color="#000000" border-top-style="solid" border-top-width=".3mm" padding-top="0.2cm"> 
       Page <fo:page-number/> of 9 
      </fo:block> 
     </fo:static-content> 
     <fo:flow flow-name="xsl-region-body"> 
      <xsl:apply-templates/> 
     </fo:flow> 
    </fo:page-sequence> 
</xsl:template> 

<xsl:template match="landscape"> 
    <fo:page-sequence master-reference="landscapeLayout" id="{generate-id(.)}"> 
     <fo:static-content flow-name="xsl-region-after"> 
      <fo:block font-size="8pt" text-align="center" border-top-color="#000000" border-top-style="solid" border-top-width=".3mm" padding-top="0.2cm"> 
       Page <fo:page-number/> of 9 
      </fo:block> 
     </fo:static-content> 
     <fo:flow flow-name="xsl-region-body"> 
      <xsl:apply-templates/> 
     </fo:flow> 
    </fo:page-sequence> 
</xsl:template> 

<xsl:template name="heading"> 
    <fo:block margin-top="10cm" font-size="21pt" font-weight="bold" text-align="center"> 
     <xsl:value-of select="heading"/> 
    </fo:block> 
    <fo:block margin-top="0.3cm" font-size="16pt" text-align="center"> 
     <xsl:text>Mailer sent: </xsl:text> 
     <xsl:value-of select="mailersent"/> 
    </fo:block> 
    <fo:block margin-top="0.3cm" font-size="16pt" text-align="center"> 
     <xsl:text>Report generated: </xsl:text> 
     <xsl:value-of select="reportgenerated"/> 
    </fo:block> 
</xsl:template> 

<xsl:template match="title"> 
    <fo:block margin-bottom="0.5cm" border-bottom-color="#000000" border-bottom-style="solid" border-bottom-width=".5mm" font-size="20pt"> 
     <xsl:value-of select="."/> 
    </fo:block> 
</xsl:template> 

<xsl:template match="graph"> 
    <fo:block margin-bottom="0.5cm" border-color="#d8d8d8" border-style="solid" border-width=".3mm" font-size="10pt"> 
     <xsl:variable name="graphimage"> 
      <xsl:value-of select="."/> 
     </xsl:variable> 
     <fo:external-graphic src="{$graphimage}" content-height="scale-to-fit" content-width="16cm" scaling="non-uniform"/> 
    </fo:block> 
</xsl:template> 

<xsl:template match="svggraph"> 
    <fo:block margin-bottom="0.5cm" border-color="#d8d8d8" border-style="solid" border-width=".3mm" font-size="10pt"> 
     <fo:instream-foreign-object xmlns:svg="http://www.w3.org/2000/svg" content-width="19cm" content-height="5cm"> 
     <svg:svg width="25" height="25"> 
     <svg:g style="fill:red; stroke:#000000"> 
     <svg:rect x="0" y="0" width="15" height="15"/> 
     <svg:rect x="5" y="5" width="15" height="15"/> 
     </svg:g> 
     </svg:svg> 
     </fo:instream-foreign-object> 
    </fo:block> 
</xsl:template> 

<xsl:template match="stats"> 
    <xsl:for-each select="stat"> 
     <fo:block margin-bottom="0.5cm" font-size="10pt"> 
      <fo:inline font-weight="bold" font-size="12pt"> 
       <xsl:value-of select="value"/> 
      </fo:inline> 
      <xsl:text> </xsl:text> 
      <xsl:value-of select="text"/> 
     </fo:block> 
    </xsl:for-each> 
</xsl:template> 

<xsl:template match="table"> 
    <fo:block> 
     <fo:table margin-bottom="0.5cm" border-collapse="separate" border-color="#d8d8d8" border-style="solid" border-width=".3mm" table-layout="fixed" width="100%" font-size="10pt"> 

      <xsl:for-each select="thead/tr/th"> 
       <xsl:choose> 
        <xsl:when test="width"> 
         <xsl:variable name="columnwidth"> 
          <xsl:value-of select="width" /> 
         </xsl:variable> 
         <fo:table-column column-width="{$columnwidth}"/> 
        </xsl:when> 
        <xsl:otherwise> 
         <fo:table-column/> 
        </xsl:otherwise> 
       </xsl:choose> 
      </xsl:for-each> 

      <fo:table-header background-color="#ededed">      
       <xsl:for-each select="thead/tr/th"> 
        <fo:table-cell padding-top="5pt" padding-bottom="5pt" padding-left="3pt" padding-right="3pt"> 
         <fo:block font-weight="bold"> 
          <xsl:value-of select="heading"/> 
         </fo:block> 
        </fo:table-cell> 
       </xsl:for-each>     
      </fo:table-header> 
      <fo:table-body>     
       <xsl:for-each select="tbody/tr">       
        <xsl:variable name="row-background"> 
         <xsl:choose> 
          <xsl:when test="position() mod 2 = 0">#f8f8f8</xsl:when> 
          <xsl:otherwise>#ffffff</xsl:otherwise> 
         </xsl:choose> 
        </xsl:variable>      
        <fo:table-row background-color="{$row-background}">       
         <xsl:for-each select="td"> 
          <fo:table-cell padding-top="5pt" padding-bottom="5pt" padding-left="3pt" padding-right="3pt"> 
           <fo:block> 
            <xsl:value-of select="."/> 
           </fo:block> 
          </fo:table-cell> 
         </xsl:for-each>       
        </fo:table-row>      
       </xsl:for-each> 
      </fo:table-body> 
     </fo:table> 
    </fo:block> 
</xsl:template> 

<xsl:template match="text"> 
    <fo:block font-size="10pt"> 
     <xsl:value-of select="."/> 
    </fo:block> 
</xsl:template> 

</xsl:stylesheet> 

UPDATE 내가 명령 줄 아래

fop -c fop_config.xml -xml /tmp/fop4IwJKZ -xsl stylesheet.xsl -pdf pdf.pdf 

에서 다음을 수행하고

내 XML이다 두 기계 모두 동일합니다. 또한 두 컴퓨터에서 XML + XSL을 XLS로 변환했습니다. FO와 두 파일은 동일합니다.

+0

나는 당신의 XML 및 스타일 시트를 사용하여 오류를 재현 할 수 없습니다를 얻을. 결과 FO 파일에는'root'의 즉각적인'블록'자식이 없습니다. – mzjn

+0

@mzjn 그것이 이상한 오류로 보이는 이유입니다. 계속 노력하겠습니다 – Pattle

+0

각 플랫폼에서 사용되는 두 개의 XSLT 프로세스는 무엇입니까? 나는 그들이 다르다는 것을 내기 할 것이다. 각 플랫폼에서 XML + XSL을 XSL FO로 형식화하고 차이점을 비교하십시오. –

답변

1

나는

C:\Users\User>cd Documents 
C:\Users\User\Documents>cd fop-1.0 
C:\Users\User\Documents\fop-1.0>fop -xsl stovfl17548663.xsl -xml stovfl17548663.xml -pdf stovfl17548663.pdf 

하여 XML 및 XSL 파일을 사용하고 난 다음 메시지

C:\Users\User\Documents\fop-1.0>fop -xsl stovfl17548663.xsl -xml stovfl17548663.xml -pdf stovfl17548663.pdf 
Sep 26, 2013 12:09:47 PM org.apache.fop.events.LoggingEventListener processEvent 
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400". 
Sep 26, 2013 12:09:47 PM org.apache.fop.events.LoggingEventListener processEvent 
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400". 
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent 
SEVERE: Image not found. URI: graphs/graph1.png. (No context info available) 
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent 
SEVERE: Image not found. URI: graphs/graph1.png. (No context info available) 
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent 
WARNING: 1 link target could not be fully resolved and now point to the top of the page or is dysfunctional. 

The resulting PDF