Loading ...
Sorry, an error occurred while loading the content.

XML data transforming to PDF using XSL-FO

Expand Messages
  • gshyun
    Hello, I am a newbie on XSLT and I have a project that needs to create a PDF files for the report results that are wrapped as Java object. I am getting an
    Message 1 of 2 , Jul 19 9:39 AM
    • 0 Attachment
      Hello,
      I am a newbie on XSLT and I have a project that needs to create a PDF
      files for the report results that are wrapped as Java object.
      I am getting an exception when I transform the java object to
      PDF, "org.apache.fop.fo.FOTreeBuilder -
      javax.xml.transform.TransformerException:
      java.lang.IllegalStateException: endElement() called for fo:page-
      sequence where there is no current element.
      file:///c:/temp/QueryResult.xsl; Line #0; Column #0;
      java.lang.IllegalStateException: endElement() called for fo:page-
      sequence where there is no current element."
      My xml file is

      <?xml version="1.0" encoding="UTF-8" ?>
      - <queryresult>
      - <rows>
      - <cols>
      <value>CapGemini U.S</value>
      </cols>
      - <cols>
      <value>02/15/2006 PST</value>
      </cols>
      - <cols>
      <value>Test Template Global</value>
      </cols>
      - <cols>
      <value>1175</value>
      </cols>
      - <cols>
      <value>CapGemini U.S</value>
      </cols>
      - <cols>
      <value>30.50</value>
      </cols>
      - <cols>
      <value>02/15/2006 PST</value>
      </cols>
      - <cols>
      <value>Screening</value>
      </cols>
      - <cols>
      <value>No</value>
      </cols>
      </rows>
      .
      .
      .
      .
      </queryresult>

      My xslt file is

      <?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" exclude-result-
      prefixes="fo">
      <xsl:output method="xml" version="1.0" omit-xml-declaration="no"
      indent="yes" />
      <xsl:param name="versionParam" select="'1.0'" />
      - <!-- =========================
      -->
      - <!-- root element: queryresult
      -->
      - <!-- =========================
      -->
      - <xsl:template match="queryresult">
      - <fo:page-sequence master-reference="simpleA4">
      - <fo:flow flow-name="xsl-region-body">
      - <fo:table table-layout="fixed" width="100%" border-
      collapse="separate">
      - <fo:table-body>
      <xsl:apply-templates select="rows" />
      </fo:table-body>
      </fo:table>
      </fo:flow>
      </fo:page-sequence>
      </xsl:template>
      - <!-- =========================
      -->
      - <!-- child element: rows
      -->
      - <!-- =========================
      -->
      - <xsl:template match="rows">
      - <fo:table-row>
      <xsl:apply-templates select="cols" />
      </fo:table-row>
      </xsl:template>
      - <!-- =========================
      -->
      - <!-- child element: cols
      -->
      - <!-- =========================
      -->
      - <xsl:template match="cols">
      - <fo:table-cell>
      <xsl:value-of select="value" />
      </fo:table-cell>
      </xsl:template>
      </xsl:stylesheet>

      Thanks in advance.
    • Joe Moore
      Change the version attribute of your xsl:stylesheet to 1.0. Version 1.1 was abandoned in favor of XSLT 2.0 and should not be used. I was able to transform
      Message 2 of 2 , Jul 19 11:58 AM
      • 0 Attachment
        Change the version attribute of your xsl:stylesheet to 1.0. Version 1.1 was abandoned in favor of XSLT 2.0 and should not be used.

        I was able to transform your xml from your xslt once I did this. I'll repost what I used.

        If you still have problems please specify what version of FOP you are using.

        <?xml version="1.0" encoding="UTF-8"?>
        <queryresult>
        <rows>
        <cols>
        <value>CapGemini U.S</value>
        </cols>
        <cols>
        <value>02/15/ 2006 PST</value>
        </cols>
        <cols>
        <value>Test Template Global</value>
        </cols>
        <cols>
        <value>1175</value>
        </cols>
        <cols>
        <value>CapGemini U.S</value>
        </cols>
        <cols>
        <value>30.50</value>
        </cols>
        <cols>
        <value>02/15/ 2006 PST</value>
        </cols>
        <cols>
        <value>Screening</value>
        </cols>
        <cols>
        <value>No</value>
        </cols>
        </rows>
        </queryresult>



        <?xml version="1.0" encoding="UTF-8"?>

        xmlns:fo="http://www.w3 org/1999/ XSL/Format"
        exclude-result-prefixes="fo">
        <xsl:output method="xml" version="1.0" omit-xml-declaration="no"
        indent="yes" />
        <xsl:param name="versionParam" select="'1.0' " />





        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.