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

Applying a XML transformation before creating the PDF (FOP)

Expand Messages
  • armin.keyvanloo@iag.com.au
    ************************************************************************** Note: This e-mail is subject to the disclaimer contained at the bottom of this
    Message 1 of 5 , Feb 9, 2004
      **************************************************************************

      Note: This e-mail is subject to the disclaimer contained at the bottom
      of this message.

      **************************************************************************
      :
      Hi,

      I need to apply a transformation to the source XML to strip out some of the
      elements from it before feeding it into FOP to create the PDF.
      I don't know how to chain the XSL's for fop. I tried using Saxon's
      next-in-chain attribute like this(transformer.xsl) by having 2 XSL's one is
      transform and one to create the PDF. I called the transformer XSL 1st (in
      the source XSL on FOP) and then use the next-in-chain to trigger the PDF
      generation:

      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
      xmlns:fo="http://www.w3.org/1999/XSL/Format";
      xmlns:fox="http://xml.apache.org/fop/entensions";
      xmlns:saxon="http://icl.com/saxon";
      version='1.0'
      exclude-result-prefixes="xsl saxon">

      <xsl:output method="xml" indent="no" saxon:next-in-chain
      ="fo-post-for-fop.xsl"/>

      <!-- Copy everything -->

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

      And I call the FOP from command line with the above XSL as the source xsl:

      fop -xml source.xml -xsl transformer.xsl my.pdf

      But this doesn't work and I get the following error:

      [ERROR] Unsupported element encountered: INSURER (Namespace: null). Source
      context: unavailable
      [ERROR] Expected XSL-FO (root, page-sequence, etc.), SVG (svg, rect, etc.)
      or elements from another supported language.
      [ERROR] java.lang.NullPointerException

      Does anyone know how to do this?
      Thanx
      Armin



      :
      ********************************************************************************

      The information transmitted in this message and attachments (if any)
      is intended only for the person or entity to which it is addressed.
      The message may contain confidential and/or privileged material.
      Any review, retransmission, dissemination or other use of, or taking
      of any action in reliance upon this information, by persons or entities
      other than the intended recipient is prohibited.

      If you have received this in error, please contact the sender and delete this
      e-mail and associated material from any computer.

      The intended recipient of this e-mail may only use, reproduce, disclose or
      distribute the information contained in this e-mail and any attached files,
      with the permission of the sender.

      This message has been scanned for viruses and cleared by MailMarshal.

      ********************************************************************
      :
    • Chris Bowditch
      ... ... FOP doesnt use Saxon out of the box, so unless youve changed the classpaths and other bits necessary FOP will use Xalan, which doesnt know
      Message 2 of 5 , Feb 10, 2004
        armin.keyvanloo@... wrote:

        > I need to apply a transformation to the source XML to strip out some of the
        > elements from it before feeding it into FOP to create the PDF.
        > I don't know how to chain the XSL's for fop. I tried using Saxon's
        > next-in-chain attribute like this(transformer.xsl) by having 2 XSL's one is
        > transform and one to create the PDF. I called the transformer XSL 1st (in
        > the source XSL on FOP) and then use the next-in-chain to trigger the PDF
        > generation:

        <snip/>

        > And I call the FOP from command line with the above XSL as the source xsl:
        >
        > fop -xml source.xml -xsl transformer.xsl my.pdf

        FOP doesnt use Saxon out of the box, so unless youve changed the
        classpaths and other bits necessary FOP will use Xalan, which doesnt
        know about next-in-chain. I'm not familiar with Saxon, so I dont know if
        it will provide what you want.

        The way I know how to achieve what you want is to write some java to
        chain the transformations together and then call FOP to process the
        result. You could also write a batch file to call xalan and then call
        FOP, but this is less efficient because the XML will need to serialised
        and re-parsed.

        The following link shows an example of running a single transformation
        then passing the result to FOP:

        http://xml.apache.org/fop/embedding.html#render-with-xslt

        This is quite straight forward to modify for two transformations.

        <snip/>

        Chris
      • J.Pietschmann
        ... First, check whether FOP really uses Saxon. If you use JDK 1.4, it is more likely you are actually using the Xalan included in the JDK, which wont
        Message 3 of 5 , Feb 10, 2004
          armin.keyvanloo@... wrote:
          > I need to apply a transformation to the source XML to strip out some of the
          > elements from it before feeding it into FOP to create the PDF.
          > I don't know how to chain the XSL's for fop. I tried using Saxon's
          > next-in-chain attribute like this(transformer.xsl) by having 2 XSL's one is
          > transform and one to create the PDF. I called the transformer XSL 1st (in
          > the source XSL on FOP) and then use the next-in-chain to trigger the PDF
          > generation:

          First, check whether FOP really uses Saxon. If you use JDK 1.4,
          it is more likely you are actually using the Xalan included in
          the JDK, which wont recognize the extension.

          If you really use Saxon, it is quite possible that the method
          how the PDF renderer is docked onto the XSLT transformer also
          ignores the required second transformation. Some possible
          approaches:
          1. Do both transformations in the same style sheet. Save the
          result from the first transformation into a variable, and
          apply the second. Use modes for the tempaltes:
          <xsl:stylesheet ...>
          <xsl:template match="/">
          <!-- start here -->
          <xsl:variable name="pass-1-result">
          <xsl:apply-templates select="." mode="pass1"/>
          </xsl:variable>
          <xsl:apply-templates select="saxon:node-set($pass-1-result)"
          mode="pass2"/>
          </xsl:template>
          <xsl:template match="/" mode="pass1">
          .... pass 1 stuff ...
          </xsl:template>
          <xsl:template match="/" mode="pass2">
          <fo:root...
          ...
          </xsl:template>
          You'll have to declare the saxon namespace in order to get the
          node-set() extension function working.
          2. Use Saxon's FOP chaining in the second XSLT. Check the Saxon
          documentation and perhaps the Saxon user list for details.
          3. Write a Java wrapper for both the transformations and FOP.
          Start here:
          http://xml.apache.org/fop/embedding.html#ExampleXML2PDF
          and use the link to the source code.
          Adding another transformation is a bit tricky, you'll have to
          check the documentation for SAXTransformerHandler and
          SAXTransformerFactory because one of the transformations has to
          be created as SAX filter.
          4. Use Cocoon:
          http://cocoon.apache.org

          J.Pietschmann
        • ArminRox
          Thanx Pietschmann, I liked the proposed same style sheet solution. ... some of the ... XSL s one is ... 1st (in ... the PDF
          Message 4 of 5 , Feb 11, 2004
            Thanx Pietschmann, I liked the proposed "same style sheet" solution.


            --- In XSL-FO@yahoogroups.com, "J.Pietschmann" <j3322ptm@y...> wrote:
            > armin.keyvanloo@i... wrote:
            > > I need to apply a transformation to the source XML to strip out
            some of the
            > > elements from it before feeding it into FOP to create the PDF.
            > > I don't know how to chain the XSL's for fop. I tried using Saxon's
            > > next-in-chain attribute like this(transformer.xsl) by having 2
            XSL's one is
            > > transform and one to create the PDF. I called the transformer XSL
            1st (in
            > > the source XSL on FOP) and then use the next-in-chain to trigger
            the PDF
            > > generation:
            >
            > First, check whether FOP really uses Saxon. If you use JDK 1.4,
            > it is more likely you are actually using the Xalan included in
            > the JDK, which wont recognize the extension.
            >
            > If you really use Saxon, it is quite possible that the method
            > how the PDF renderer is docked onto the XSLT transformer also
            > ignores the required second transformation. Some possible
            > approaches:
            > 1. Do both transformations in the same style sheet. Save the
            > result from the first transformation into a variable, and
            > apply the second. Use modes for the tempaltes:
            > <xsl:stylesheet ...>
            > <xsl:template match="/">
            > <!-- start here -->
            > <xsl:variable name="pass-1-result">
            > <xsl:apply-templates select="." mode="pass1"/>
            > </xsl:variable>
            > <xsl:apply-templates select="saxon:node-set($pass-1-result)"
            > mode="pass2"/>
            > </xsl:template>
            > <xsl:template match="/" mode="pass1">
            > .... pass 1 stuff ...
            > </xsl:template>
            > <xsl:template match="/" mode="pass2">
            > <fo:root...
            > ...
            > </xsl:template>
            > You'll have to declare the saxon namespace in order to get the
            > node-set() extension function working.
            > 2. Use Saxon's FOP chaining in the second XSLT. Check the Saxon
            > documentation and perhaps the Saxon user list for details.
            > 3. Write a Java wrapper for both the transformations and FOP.
            > Start here:
            > http://xml.apache.org/fop/embedding.html#ExampleXML2PDF
            > and use the link to the source code.
            > Adding another transformation is a bit tricky, you'll have to
            > check the documentation for SAXTransformerHandler and
            > SAXTransformerFactory because one of the transformations has to
            > be created as SAX filter.
            > 4. Use Cocoon:
            > http://cocoon.apache.org
            >
            > J.Pietschmann
          • J.Pietschmann
            ... It is said this may cause a noticable performance hit compared to using a Java wrapper for chaining. The problem ought to be fixed with recent Saxon 7.x
            Message 5 of 5 , Feb 12, 2004
              ArminRox wrote:
              > Thanx Pietschmann, I liked the proposed "same style sheet" solution.

              It is said this may cause a noticable performance hit compared
              to using a Java wrapper for chaining. The problem ought to be
              fixed with recent Saxon 7.x releases. If you experience this
              problem, ask on the Saxon lists for help.

              J.Pietschmann
            Your message has been successfully submitted and would be delivered to recipients shortly.