Peter.Schulte at gad.de wrote:
> as documented in another thread I'm using the process command
> copyDocument for creating and replacing document parts with references.
> My problem is that copyDocument changes the filerefs in the newly
> created document part and these filerefs become wrong.
> 
> Let me explain it with a sample. We always use the following
> directory-structure for DocBook-documents:
> 
> - ...
>   - docs
>     - docs-main            <<< for books, articles
>     - docs-parts           <<< for referenced parts (chapters, sections,
> ...)
>     - figures
>     - ...
> 
> This is the original "main-document" in docs/docs-main:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE book PUBLIC "-//GAD//DTD DocBook XML V4.2-Variant//EN"
> "../../../import/dochb_zentral/docbook/docbook-xml-4.2/gad-docbookx.dtd">
> <book lang="de">
>   <title>Buchtitel</title>
>   <chapter>
>     <title>Dies ist ein Kapitel</title>
>     <section>
>       <title>Dies ist ein Abschnitt</title>
>       <para>Dies ist ein para</para>
>     </section>
>   </chapter>
>   <chapter>
>     <title>This is a chapter</title>
>     <section>
>       <title>This is a section</title>
>       <para>para</para>
>       <figure>
>         <title>test figure</title>
>         <mediaobject>
>           <imageobject>
>             <imagedata fileref="../figures/Test.png" />
>           </imageobject>
>         </mediaobject>
>       </figure>
>     </section>
>   </chapter>
> </book>
> 
> 
> Then I call a macro command which calls the following process command:
> 
>   <command name="copy-docu">
>     <process>
>       <copyDocument to="%0"    <<< this is
> ../docs-parts/test-chapter-reference.xml

***Warning, Warning, Warning,*** relative references are relative to the
temporary working directory created during the execution of the process
command. They are not relative to the directory containing the document
being edited.



>           selection = "true"
>           preserveEntityRefs = "false"
>           preserveXIncludes = "true"
>           indent="true"
>           encoding="ISO-8859-1" />
>       <read file="%0" encoding="ISO-8859-1" />
>     </process>
>   </command>
> 
> This is the newly created part of the main-document:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE chapter PUBLIC "-//GAD//DTD DocBook XML V4.2-Variant//EN"
> "../../../import/dochb_zentral/docbook/docbook-xml-4.2/gad-docbookx.dtd">
> <chapter>
>   <title>This is a chapter</title>
>   <section>
>     <title>This is a section</title>
>     <para>para</para>
>     <figure>
>       <title>test figure</title>
>       <mediaobject>
>         <imageobject>
>           <imagedata fileref="./Test.png" />       <<< this is wrong
>         </imageobject>
>       </mediaobject>
>     </figure>
>   </section>
> </chapter>
> 
> 
> This is the new "main-document" with a reference to the part in
> .../docs/docs-parts:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE book PUBLIC "-//GAD//DTD DocBook XML V4.2-Variant//EN"
> "../../../import/dochb_zentral/docbook/docbook-xml-4.2/gad-docbookx.dtd">
> <book lang="de">
>   <title>Buchtitel</title>
>   <chapter>
>     <title>Dies ist ein Kapitel</title>
>     <section>
>       <title>Dies ist ein Abschnitt</title>
>       <para>Dies ist ein para</para>
>     </section>
>   </chapter>
> 
>   <xi:include href="../docs-parts/test-chapter-reference.xml"
>               xmlns:xi="http://www.w3.org/2001/XInclude";
>               xpointer="element(/1)" />
> </book>
> 
> 
> The fileref has been automatically changed by copyDocument. Either it
> should have been preserved or it should have been refreshed:
> in both cases the result should have been:  ../figures/Test.png
> 
> Is it a bug or can you explain, why the fileref was changed to
> ./Test.png? Or what can I do to preserve the filerefs?

No, there is no bug here.

The job of copyDocument is to copy the document *along with all its
resources* to another place (generally the temporary directory of the
process command).

In order to do this, it generally makes sense to change the filerefs.

If you take the time to carefully read the documentation of
copyDocument, you'll find that dealing with document resources  can be
parametrized using *rules*. See
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/copyDocument.html#resources

The *default* rules are:
---
<resources match="(https|http|ftp)://.*" />
<resources match=".+" copyTo="." />
---

If you explicitly specify the rule below, then you are done:
copyDocument will ignore all references to resources (found in filerefs
in the case of DocBook).
---
<resources match=".*" />
---



> By the way I have another question:
> The process command copyDocument creates the file with <!DOCTYPE
> chapter.... So the following " include-replace"-command does (can) not
> use entities for the reference in the main document. Instead it uses
> xi:include with xpointer. How can I manage to get entity-references?

This would be illegal XML. An external entity cannot have a <!DOCTYPE>.
Only a document can. That's why xi:include with xpointer is used instead.

You need to strip the <!DOCTYPE> from the copied document, for example
by using a transform element
(http://www.xmlmind.com/xmleditor/_distrib/doc/commands/transform.html)
with a trivial XSLT style sheet.


Reply via email to