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

Re: [XSL-FO] Applying a XML transformation before creating the PDF (FOP)

Expand Messages
  • 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 1 of 5 , Feb 10 1:18 AM
    • 0 Attachment
      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 2 of 5 , Feb 10 11:38 AM
      • 0 Attachment
        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 3 of 5 , Feb 11 9:19 PM
        • 0 Attachment
          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 4 of 5 , Feb 12 12:20 PM
          • 0 Attachment
            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.