Forum How do I...?

Any chance of a how-to for creating links/cross-references?

David J Prokopetz
Hi.

This isn't so much a how-to as a request for documentation: do you have the requirements for creating links and cross-references in arbitrary XML documented anywhere?

Your current documentation ( http://www.princexml.com/doc/6.0/cross-references/ ) only addresses the matter for HTML, and provides only part of the picture besides. I find that when I'm working with non-HTML documents, I always forget some necessary step or other (e.g., what attribute(s) the link target needs to possess, etc.), and it can be pretty frustrating to determine why all my page references are coming up "p. 0". It would be very helpful if the minimal set of steps was written down somewhere - and sadly, I'm not sure my understanding is comprehensive enough to write it up myself (as evidenced by the fact that I keep forgetting stuff). :oops:

Basically, my question is this: at a bare minimum, what attributes and CSS properties do I need to stick on each of the linking element and its target element to make sure the link actually works?

Thanks,

- Dave.
David J Prokopetz
Hmmm. I suspect I may be running into a bug here. See:

http://www.princexml.com/bb/viewtopic.php?t=1132
mikeday
The trouble is when a document is XIncluded from another directory, the XInclude processor will add an xml:base attribute to the root element, so that relative links are preserved. For example:
<include href="chapters/chapter1.xml"/>

expands to:
<chapter id="chapter_1" xml:base="chapters/chapter1.xml">
...
</chapter>

Within the document, a link to #chapter_3 will be relative to the current base URL, so it becomes chapters/chapter1.xml#chapter3, which doesn't point anywhere useful.

The answer would appear to be to change the link to be chapter3.xml#chapter_3, but Prince isn't expecting different document names within the same document, so that won't get resolved either. We're going to need to look at this issue of internal links between different XIncluded documents, as right now it seems difficult to do. (External XML entities should not have this problem, as they are not given xml:base attributes).
David J Prokopetz
Hmmm. I realise that the way I'm doing things may not be the most appropriate method, but I do have two further questions:

1. Is there any way that this behaviour could be made consistent? That this type of cross-reference may or may not work depending on the location of the included document is what threw me in the first place. I probably would have figured it out more quickly if all of the cross-references were failing rather than just some of them.

2. Is there a more appropriate method of pulling these files in that won't mess up the cross-references? I suppose my request for documentation still stands - it would be handy to know what Prince "expects" in situations like this.

Thanks,

- Dave.
ddeyen
mikeday wrote:
(External XML entities should not have this problem, as they are not given xml:base attributes).


Can you give me an example of an external XML entity.

In my specific application of Prince I am trying to link together many different XML files (in many directories) using an html file full of xincludes. As long as the files are in the same directory the links work fine but once I xinclude a file from a different directory none of the links work. I haven't seen any traffic on this thread in sometime so perhaps its been solved elsewhere. Any help is appreciated I've been trying to get an acceptable workaround for this for a long time.
mikeday
Here is an example of using external parsed entities to include multiple XML documents into one document:
<?xml version="1.0"?>
<!DOCTYPE html [
  <!ENTITY chap1 SYSTEM "/path/to/chapter1.xml">
  <!ENTITY chap2 SYSTEM "/path/to/chapter2.xml">
]>
<html>
<body>
&chap1;
&chap2;
</body>
</html>

This technique predates XInclude, and in fact predates XML, as it is inherited from SGML, hence the unusual syntax.