xsl-list
[Top] [All Lists]

Re: Identity of Documents Puzzle

2002-12-06 20:17:59
G. Ken Holman wrote:
At 2002-12-06 18:08 -0600, W. Eliot Kimber wrote:

My question: is there any way, other than passing in the filename of the top-level file as a parameter to the style sheet, to ensure that the node for the document as created by the initial style sheet processing is the same as one for a call to document() for the same file (it may or may not be the same filename depending on the relative locations of the files involved)? I can't think of one, but there are many subtleties of XSLT that I have yet to master.


When I've needed to guarantee unique identifiers from multiple documents, I just change every identifier to its generated identifier and the resulting document is self-referentially ID/IDREF okay.

Unfortunately, the problem in this case is not the ID rewriting itself, but knowing *when* to do the rewriting. The problem is that for links that go outside of the compound document that contains the link, I just need to get the element referenced so I can get the properties I need to render the cross reference (e.g., the title of a section) but since I am rendering to FO (and not HTML), I have no way at the moment to construct a working cross-document link in the PDF (because no FO implementations yet enable the creation of PDF-specific cross-document links, as far as I know). So for cross-compound-document links, I don't want to do any rewriting because when I process the transcluded result to create the final FO rendition, I will want to resolve the link against its original document, not a locally processed copy.

Here's the processing steps I currently go through:

1. In my base template for "/", redirect to a new mode, "xinclude", that constructs a new result tree in which all includes are resolved and all IDs are rewritten to be unique (using the generate-id() mechanism ]although now that I think about it, that's not good enough if the same element is transcluded twice--I have to qualify it by its inclusion ancestry. Hmph. This may require more infrastructure than I can implement in XSLT alone.]).

2. Write this transcluded result to a temporary file in the same file system location as the top-level document (so that any relative paths will be relative to the input document and not the style sheet).

3. Using the document() function, process the transcluded result document using the normal style sheet templates to produce an FO result instance. As part of this process, any cross references will be resolved in order to generate the appropriate output result, i.e., titles, captions, numbers, etc.

So, by building up a list of all the docs that are included, I can know if any given target document is in the BOS or not and therefore know whether to rewrite the reference to be local to the transcluded result or not. But not for the top-level document. It sounds like passing in the filename is my only hope, and even then, it may not work if identity is only based on URI and not file object identity.

Note that this approach doesn't completely satisfy all the requirements. If a given reference target is included multiple times, then you need a way to address it within the context of a specific use (that is, WRT to a single inclusion path). Conceptually this is pretty easy: you just identify the top-level document of the target compound document and then identify each of the xi:include elements in the inclusion path, e.g., something like:

In mydoc.xml:

<xref
  use-context="yourdoc.xml#xi-01, xi-34"
  ref-target="xpointer(para[4])"
/>

yourdoc.xml:

<?xml version="1.0"?>
<yourdoc xmlns:xi="http://www.w3.org/2001/XInclude";>
  ...
  <xi:include id=xi-01" href="subdoc-01.xml"/>
  ..
</yourdoc>

subdoc-01.xml:

<?xml version="1.0"?>
<yourdoc xmlns:xi="http://www.w3.org/2001/XInclude";>
  ...
  <xi:include id=xi-34" href="subdoc-02.xml"/>
  <xi:include id=xi-35" href="subdoc-02.xml"/>
  ...
</yourdoc>

subdoc-02.xml:

<?xml version="1.0"?>
<yourdoc>
<para/>
<para/>
<para/>
<para>This is the fourth parth</para>
</yourdoc>

Note that subdoc-02.xml is include twice, but the initial crossref is to the first use of para[4] in subdoc-02.xml, not the second, and not both (which would be a reasonable default behavior if a use context is not specified).

I haven't had a chance to work out the best syntax for this in the context of the document type I'm currently working with, but the basic mechanism is clear enough in principle

Cheers,

Eliot
--
W. Eliot Kimber, eliot(_at_)isogen(_dot_)com
Consultant, ISOGEN International

1016 La Posada Dr., Suite 240
Austin, TX  78752 Phone: 512.656.4139


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>