You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by jantje <ja...@skynet.be> on 2008/06/19 21:32:40 UTC

Include a complete file in FOP

Hi there, I use Apache Fop to generate PDF from the file text.xml

In this file there is text, but also this element:
<includeXmlFile>
  <path>source/xml/</path>
  <file>file.xml</file>
</includeXmlFile>

So, in PDF I want to show the complete content from file.xml, so also the
elements and attributes.

I use this, in xsl, to generate a .fo -file:
  <xsl:template match="includeXmlFile">
    <xsl:variable name="source">
      <xsl:value-of select="string('../../../')"/>
      <xsl:value-of select="path"/>
      <xsl:value-of select="file"/>
    </xsl:variable>
    <xsl:for-each select="document($source)">
        <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
    </xsl:for-each>
  </xsl:template>

But this does not seem to work. ($source is ok, so only the copy part does
not work)

Anyone an idea? Thanks..
-- 
View this message in context: http://www.nabble.com/Include-a-complete-file-in-FOP-tp18016418p18016418.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Include a complete file in FOP

Posted by "J.Pietschmann" <j3...@yahoo.de>.
jantje wrote:
> So, in PDF I want to show the complete content from file.xml, so also the
> elements and attributes.

I suppose you want to have the content of file.xml rendered as
kind of "XML source code". Well....

 > But this does not seem to work.

The standard answer to this phrase is: What do you mean by
"does not work"? Did you get an error message, and if so,
what did it say?
In your specific case, there are multiple probles in your XSLT:

>    <xsl:template match="includeXmlFile">
>      <xsl:variable name="source">
>        <xsl:value-of select="string('../../../')"/>
>        <xsl:value-of select="path"/>
>        <xsl:value-of select="file"/>
>      </xsl:variable>
It is better to write this as
  <xsl:variable name="source" select="concat('../../../',path,file)" />

>      <xsl:for-each select="document($source)">
The document() function returns a single node, the root node
of the document, therefore the for-each doesn't do much (except
context switching).

>          <xsl:copy>
This copies the document root node, which isn't very useful.

> <xsl:apply-templates select="node()|@*"/>
This starts traversal of the XML tree read from file. I guess
you just got the text from the file in the PDF, without the
tags, which is the result of recursively applying the default
template.

If you want to get the file content as "XML source", you have to
render it yourself as text. If you use an XSLT 1.0 processor, you
can search the XSLT FAQ or the XSL list archives for code doing
this (there were multiple publications in the past). This wont
give you an exact copy of the sourec XML, because some information
is lost during XML parsing. If you can preprocess the XML file using
another tool, you can enclose the content in a CDATA section. An
XSLT 2.0 processor has the capability to read text files unparsed,
which is another possibility.

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Include a complete file in FOP

Posted by bonekrusher <dj...@yahoo.com>.


jantje wrote:
> 
> Hi there, I use Apache Fop to generate PDF from the file text.xml
> 
> In this file there is text, but also this element:
> <includeXmlFile>
>   <path>source/xml/</path>
>   <file>file.xml</file>
> </includeXmlFile>
> Try:
> 
>   <xsl:template match="includeXmlFile">
>     <xsl:variable name="source">
>       <xsl:value-of select="string('../../../')"/>
>       <xsl:value-of select="path"/>
>       <xsl:value-of select="file"/>
>     </xsl:variable>
>     <xsl:for-each select="document($source)">
>         	<xsl:copy>
> 			<xsl:copy-of select="@*"/>
> 			<xsl:apply-templates/>
> 		</xsl:copy>
>     </xsl:for-each>
>   </xsl:template>
> 
> Regards,
> 
> Bones
> 
> 
> So, in PDF I want to show the complete content from file.xml, so also the
> elements and attributes.
> 
> I use this, in xsl, to generate a .fo -file:
>   <xsl:template match="includeXmlFile">
>     <xsl:variable name="source">
>       <xsl:value-of select="string('../../../')"/>
>       <xsl:value-of select="path"/>
>       <xsl:value-of select="file"/>
>     </xsl:variable>
>     <xsl:for-each select="document($source)">
>         <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
>     </xsl:for-each>
>   </xsl:template>
> 
> But this does not seem to work. ($source is ok, so only the copy part does
> not work)
> 
> Anyone an idea? Thanks..
> 

-- 
View this message in context: http://www.nabble.com/Include-a-complete-file-in-FOP-tp18016418p18076215.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org