You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Ross Gardler <rg...@wkwyw.net> on 2002/08/06 19:18:01 UTC
executing XInclude transformer twice
I have a problem with XInclude, however, I may be using the wrong
solution in the first place, that is perhaps I should be using some
other mechanism for achieving what I want. So solutions that use a
technique other than XInclude are welcome.
I have a book written in XML and divided into a number of chapters
introduction.xml
background.xml
casestudies.xml
etc.
Within each chapter I use XInclude to bring some content from other
files available on a web site, for example, glossary and program code,
so my pipeline matcher (for pdf output) is:
<map:match pattern="**.pdf">
<map:generate src="content/xdocs/{1}.xml"/>
<map:transform type="xinclude"/>
<map:transform src="skins/saafe/xslt/fo/document2fo.xsl"/>
<map:serialize type="fo2pdf"/>
</map:match>
This all works fine for individual chapters, but...
To produce the full book, that is a single document with all chapters
included, I have another xml file (called full.xml) that includes the
relative portions of the chapter xml files, for example:
<document>
<header>
...
</header>
<body>
<chapter>
<xi:include href="introduction.xml#xpointer(/document/header)"/>
<xi:include href="introduction.xml#xpointer(/document/body)"/>
</chapter>
<chapter>
<xi:include href="background.xml#xpointer(/document/header)"/>
<xi:include href="background.xml#xpointer(/document/body)"/>
</chapter>
...
</body>
</document>
Predictably, what I get is a document including most of the information
from the chapter files, but not the included information within each of
the chapter files. That is, assume background.xml has an xinclude within
it, this is not translated by the pipeline.
I have tried adding a second xinclude transform the the pipeline:
<map:match pattern="**.pdf">
<map:generate src="content/xdocs/{1}.xml"/>
<map:transform type="xinclude"/>
<map:transform type="xinclude"/> <!-- second transformation becasue
included files may have includes -->
<map:transform src="skins/saafe/xslt/fo/document2fo.xsl"/>
<map:serialize type="fo2pdf"/>
</map:match>
This generates an error stating that full.xml cannot be found in the
build directory. I have verified that it is there, and of course it is.
I don;t think it is a path problem becasue full.xml and all the chapter
xml files are all in the same directory and all chapters generate OK
when there is only a single include transformation in the pipeline.
Even if this were to work there would be a problem. What if we needed
three transformations, or four, or five etc. It is perfectly possible
for includes to include includes and so on.
Note, I am a relatively competant programmer, so if this is a limitation
of the XInclude transformer and it is within the specs of XInclude to
have such recursion I will gladly add it to the transformer.
Thanks for any input,
Ross
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: executing XInclude transformer twice
Posted by Joerg Heinicke <jo...@gmx.de>.
Hello Ross,
XInclude is only for including some XML snippets as you have used it.
It's not for recursive use and there is no need for it I think. Use a
technology like XSLT which can do what you want.
An example:
Instead of an XInclude ref in the file you can write:
<document>
<header>
...
</header>
<body>
<chapter href="introduction.xml"/>
<chapter href="background.xml"/>
...
</body>
</document>
The stylesheet would look like the following:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Tranform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="chapter[@href]">
<xsl:apply-templates select="document(@href)/document/header"/>
<xsl:apply-templates select="document(@href)/document/body"/>
</xsl:template>
</xsl:stylesheet>
This would work recursively too.
Regards,
Joerg
Ross Gardler wrote:
> I have a problem with XInclude, however, I may be using the wrong
> solution in the first place, that is perhaps I should be using some
> other mechanism for achieving what I want. So solutions that use a
> technique other than XInclude are welcome.
>
> I have a book written in XML and divided into a number of chapters
>
> introduction.xml
> background.xml
> casestudies.xml
> etc.
>
> Within each chapter I use XInclude to bring some content from other
> files available on a web site, for example, glossary and program code,
> so my pipeline matcher (for pdf output) is:
>
> <map:match pattern="**.pdf">
> <map:generate src="content/xdocs/{1}.xml"/>
> <map:transform type="xinclude"/>
> <map:transform src="skins/saafe/xslt/fo/document2fo.xsl"/>
> <map:serialize type="fo2pdf"/>
> </map:match>
>
> This all works fine for individual chapters, but...
>
> To produce the full book, that is a single document with all chapters
> included, I have another xml file (called full.xml) that includes the
> relative portions of the chapter xml files, for example:
>
> <document>
> <header>
> ...
> </header>
> <body>
> <chapter>
> <xi:include href="introduction.xml#xpointer(/document/header)"/>
> <xi:include href="introduction.xml#xpointer(/document/body)"/>
> </chapter>
> <chapter>
> <xi:include href="background.xml#xpointer(/document/header)"/>
> <xi:include href="background.xml#xpointer(/document/body)"/>
> </chapter>
> ...
> </body>
> </document>
>
> Predictably, what I get is a document including most of the information
>
>> from the chapter files, but not the included information within each of
>
> the chapter files. That is, assume background.xml has an xinclude within
> it, this is not translated by the pipeline.
>
> I have tried adding a second xinclude transform the the pipeline:
>
> <map:match pattern="**.pdf">
> <map:generate src="content/xdocs/{1}.xml"/>
> <map:transform type="xinclude"/>
> <map:transform type="xinclude"/> <!-- second transformation becasue
> included files may have includes -->
> <map:transform src="skins/saafe/xslt/fo/document2fo.xsl"/>
> <map:serialize type="fo2pdf"/>
> </map:match>
>
> This generates an error stating that full.xml cannot be found in the
> build directory. I have verified that it is there, and of course it is.
> I don;t think it is a path problem becasue full.xml and all the chapter
> xml files are all in the same directory and all chapters generate OK
> when there is only a single include transformation in the pipeline.
>
> Even if this were to work there would be a problem. What if we needed
> three transformations, or four, or five etc. It is perfectly possible
> for includes to include includes and so on.
>
> Note, I am a relatively competant programmer, so if this is a limitation
> of the XInclude transformer and it is within the specs of XInclude to
> have such recursion I will gladly add it to the transformer.
>
> Thanks for any input,
> Ross
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
RE: executing XInclude transformer twice
Posted by Leigh Dodds <ld...@ingenta.com>.
> -----Original Message-----
> From: Ross Gardler [mailto:rgardler@wkwyw.net]
> Sent: 06 August 2002 18:18
> To: cocoon-users@xml.apache.org
> Subject: executing XInclude transformer twice
>
...
> Predictably, what I get is a document including most of the information
> from the chapter files, but not the included information within each of
> the chapter files. That is, assume background.xml has an xinclude within
> it, this is not translated by the pipeline.
...
Rather than XInclude the documents directly in the main content document,
can't you include them via a Cocoon pipeline?
In other words, set up pipelines for each chapter which does the lowest
level of include. Then change the book XML document to include a full, rather
than relative URL of the document.
I've not tried this, but it ought to work.
Let me know if it's successful, and I'll capture the information as a HOW-TO.
Cheers,
L.
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>