2012-12-03 3 views
0

다음 명령에서 apache-fop을 사용하여 pdf를 생성하려고합니다. 이내 xsl-fo 코드의 문제점

<?xml version="1.0" encoding="iso-8859-1"?> 
<service> 
    <serviceId>11111</serviceId> 
    <openDate>2012-02-16</openDate> 
    <closeDate>2012-02-16</closeDate> 
    <description>INSPECT MACHINE</description> 
    <repairCost>$266.76</repairCost> 
</service> 

내 XSLT XSL-FO 파일이 나는 오류가 발생하고이

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.1" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format" 
    > 
    <xsl:output encoding="iso-8859-1" /> 
    <xsl:template match ="Service"> 
     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
      <fo:layout-master-set> 
       <fo:simple-page-master master-name="Service"> 
        <fo:region-body></fo:region-body> 
       </fo:simple-page-master> 
      </fo:layout-master-set> 

      <fo:page-sequence master-reference="Service"> 
       <fo:flow flow-name="xsl-region-body"> 
        <fo:block> 
         <fo:table> 
          <fo:table-body> 
           <fo:table-row> 
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Service Id</fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Open Date</fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Close Date</fo:block> 
            </fo:table-cell>          
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Order Status</fo:block> 
            </fo:table-cell>          
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Description</fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px black" 
            text-align="center" font-weight="bold"> 
             <fo:block>Repair Cost</fo:block> 
            </fo:table-cell> 
           </fo:table-row> 
           <xsl:for-each select="./servicetype"> 
            <fo:table-row> 
             <fo:table-cell border="solid 1px bold" text-align="center"> 
              <fo:block><xsl:value-of select="serviceId" /></fo:block> 
             </fo:table-cell> 
             <fo:table-cell border="solid 1px bold" text-align="center"> 
              <fo:block><xsl:value-of select="openDate" /></fo:block> 
             </fo:table-cell> 
             <fo:table-cell border="solid 1px bold" text-align="center"> 
              <fo:block><xsl:value-of select="closeDate" /></fo:block> 
             </fo:table-cell>         

             <fo:table-cell border="solid 1px bold" text-align="center"> 
              <fo:block><xsl:value-of select="description" /></fo:block> 
             </fo:table-cell> 
             <fo:table-cell border="solid 1px bold" text-align="center"> 
              <fo:block><xsl:value-of select="repairCost" /></fo:block> 
             </fo:table-cell> 
            </fo:table-row> 
           </xsl:for-each> 
          </fo:table-body> 
         </fo:table> 
        </fo:block> 
       </fo:flow> 
      </fo:page-sequence> 
     </fo:root> 
    </xsl:template> 
</xsl:stylesheet> 

모양처럼

C:\fop-1.0-bin\fop-1.0>fop -xml sample1.xml -xsl xsl-fo.xsl -pdf sample2.pdf

내 XML 보인다. 누군가 코드에서 내 오류를 지적 할 수 있습니까? 나는이 예에게 foreach 문에 XPath를 변경 http://www.codeproject.com/Articles/37663/PDF-Generation-using-XSLFO-and-FOP

SEVERE: org.apache.fop.fo.ValidationException: Document is empty (something migh 
t be wrong with your XSLT stylesheet). 
Dec 3, 2012 4:27:27 PM org.apache.fop.cli.Main startFOP 
SEVERE: Exception 
javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: 
Document is empty (something might be wrong with your XSLT stylesheet). 
     at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:302) 
     at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130) 
     at org.apache.fop.cli.Main.startFOP(Main.java:174) 
     at org.apache.fop.cli.Main.main(Main.java:205) 
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.Validatio 
nException: Document is empty (something might be wrong with your XSLT styleshee 
t). 
     at org.apache.xalan.transformer.TransformerImpl.transformNode(Transforme 
rImpl.java:1430) 
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp 
l.java:709) 
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp 
l.java:1284) 
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp 
l.java:1262) 
     at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:299) 
     ... 3 more 
Caused by: org.apache.fop.fo.ValidationException: Document is empty (something m 
ight be wrong with your XSLT stylesheet). 
     at org.apache.fop.events.ValidationExceptionFactory.createException(Vali 
dationExceptionFactory.java:38) 
     at org.apache.fop.events.EventExceptionManager.throwException(EventExcep 
tionManager.java:54) 
     at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBr 
oadcaster.java:175) 
     at $Proxy0.emptyDocument(Unknown Source) 
     at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:158) 
     at org.apache.xml.serializer.ToXMLSAXHandler.endDocument(ToXMLSAXHandler 
.java:181) 
     at org.apache.xalan.transformer.TransformerImpl.transformNode(Transforme 
rImpl.java:1378) 
     ... 7 more 
+0

XSLT 1.1은 버려진 초안이므로 사용해서는 안됩니다. –

답변

1

시도를 다음입니다

<xsl:for-each select="./service"> 

XML :

<?xml version="1.0" encoding="iso-8859-1"?> 
<services> 
    <service> 
     <serviceId>11111</serviceId> 
     <openDate>2012-02-16</openDate> 
     <closeDate>2012-02-16</closeDate> 
     <orderStatus>Status2</orderStatus> 
     <description>INSPECT MACHINE</description> 
     <repairCost>$266.76</repairCost> 
    </service> 
    <service> 
     <serviceId>11111</serviceId> 
     <openDate>2012-02-16</openDate> 
     <closeDate>2012-02-16</closeDate> 
     <orderStatus>Status1</orderStatus> 
     <description>INSPECT MACHINE</description> 
     <repairCost>$266.76</repairCost> 
    </service> 
</services> 

XSL :

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.1" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
<xsl:output encoding="iso-8859-1" /> 
<xsl:template match ="services"> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     <fo:layout-master-set> 
      <fo:simple-page-master master-name="service"> 
       <fo:region-body></fo:region-body> 
      </fo:simple-page-master> 
     </fo:layout-master-set> 

     <fo:page-sequence master-reference="service"> 
      <fo:flow flow-name="xsl-region-body"> 
       <fo:block> 
        <fo:table> 
         <fo:table-body> 
          <fo:table-row> 
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Service Id</fo:block> 
           </fo:table-cell> 
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Open Date</fo:block> 
           </fo:table-cell> 
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Close Date</fo:block> 
           </fo:table-cell>          
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Order Status</fo:block> 
           </fo:table-cell>          
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Description</fo:block> 
           </fo:table-cell> 
           <fo:table-cell border="solid 1px black" 
           text-align="center" font-weight="bold"> 
            <fo:block>Repair Cost</fo:block> 
           </fo:table-cell> 
          </fo:table-row> 
          <xsl:for-each select="./service"> 
           <fo:table-row> 
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="serviceId" /></fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="openDate" /></fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="closeDate" /></fo:block> 
            </fo:table-cell>         
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="orderStatus" /></fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="description" /></fo:block> 
            </fo:table-cell> 
            <fo:table-cell border="solid 1px bold" text-align="center"> 
             <fo:block><xsl:value-of select="repairCost" /></fo:block> 
            </fo:table-cell> 
           </fo:table-row> 
          </xsl:for-each> 
         </fo:table-body> 
        </fo:table> 
       </fo:block> 
      </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
</xsl:template> 
</xsl:stylesheet> 
+0

작동하지 않습니다. 여전히 동일한 오류가 발생합니다 – user525146

+0

같은 템플릿 일치를 얻는 것이 중요합니다. 또한 xml 파일에는 services라는 루트가 있어야합니다. 나는 이것을 시도하고 pdf를 생성한다 –

+0

당신은 ans에 넣은 코드를 복사하고, 태그를 체크하고, 시도했다. 실패했다. – user525146

2

그것은 간단 할 수 사건의 문제로? 샘플 XML은 <service>을 루트 태그로 사용하지만 <xsl:template match="Service"> (대문자 S)입니다. 대신 자동 테이블 레이아웃을 지원하지 않는

0

FOP는 고정 테이블 레이아웃을 사용

자동 레이아웃은 FOP 지원하지 않는 페이지는 고정 폭 같이 A4, A3 ...]

http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-dev/200510.mbox/%[email protected]%3E 

http://wiki.apache.org/xmlgraphics-fop/Troubleshooting/CommonLogMessage 

참고 : 당신이 테이블이며 특별한해야 경고를 방지하기 위해 자동 모드는 페이지의 크기가 (..., 해상도에 따라 창 크기 조정) 참조를 변경할 수 있기 때문에 HTML을 rendring에서 지원됩니다 -layout = "fixed", 열 정의시 width = "100 %"및 "*"사용 widht