Forum How do I...?

Cross-references and heading numbering with XInclude

david_baker
I am evaluating PrinceXML as a solution for my company to produce software documentation for some very modular software. As the software is modular, we would also like the manuals to be modular, so we have the document setup as a number of xhtml documents which are XIncluded into a template document. We are also externally generating a table of contents, which is also being XIncluded. We are having two problems however.

Section Numbering
We cannot get the sections to number properly. The first level section number works OK, but the remaining levels (2 & 3) only seem to reset for the scope of the file the headings are located in. This results in heading numbering like:
1
1.1 (same file as 1)
1.2 (different file to 1.1)
1.3 (different file to 1.2)
2 (different file again)
2.1 (same file as 2)
2.4 (different file)
2.5 (same file as 2.5)
3 (new file)
3.1 (same file)
3.2 (same file)
3.6 (new file)

If we copy everything into one file it works OK - but that defeats the goal of its being modular and re-usable.

The style sheets I have setup (a little simplified) are:
h1
	{
	counter-increment: head1;
	counter-reset: head2 0 head3 0; 
	page-break-before:always;
	page-break-after:avoid;
	string-set: section-title content();
	}

h2
	{
	counter-reset: head3; 
	counter-increment: head2;
 	page-break-after:avoid;
	}

h3
	{
 	page-break-after:avoid;
	counter-increment: head3; 
	}
	
h4
	{
                page-break-after:avoid;
	}
	
h3::before 
	{ 	
	content: counter(head1)"."counter(head2)"."counter(head3)"  "  
	}

h2::before 
	{ 	
	content: counter(head1)"."counter(head2)"  "  
	}

h1::before 
	{ 	
	content: counter(head1)"  "  
	}


Am I doing something wrong in this style sheet?

XIncluded Table of Contents
As mentioned above, we are attempting to XInclude a table of contents which has been generated to reference all of the headings in the document across each of the files. We are generating XHTML code like:
  <h1 class="unnumbered">Contents</h1><UL>
<li class="toc1"><a href="C:\html\INTRODUCTION.html#Introduction">Introduction</a></li>
<UL>
<li class="toc2"><a href="C:\html\ABOUT.html#AboutRa">About The Software</a></li>
<li class="toc2"><a href="C:\html\FEATURES.html#RaFeatures">Features</a></li>
<li class="toc2"><a href="C:\html\CONVENTIONS.html#Conventions">Conventions</a></li>
<li class="toc2"><a href="C:\html\GETTING_HELP.html#GettingHelp">Getting Help</a></li>
<li class="toc2"><a href="C:\html\OVERVIEW.html#Overview">Overview</a></li>
</UL>
<li class="toc1"><a href="C:\html\THE_INTERFACE.html#Interface">
      The Interface
    </a></li>


with CSS like:
li.toc1, li.toc1 a[href]
{
margin-left:0cm; 
list-style: none;
color: #000000;
text-decoration: none;
font-weight: bold;
}

li.toc1 a[href]::after
{
content: leader(".") target-counter(attr(href), page)
}


However when the TOC is rendered all page references appear as '0'. Again this works if all of the sections are copied into one document, but not using XInclude.

Is there any way to make these cross-document references work on Price 6 rev 6?
leif
To the first issue, yes, there is awareness about an issue with counter-reset. Apparenty Prince currently links counter-reset to the BODY element of each HTML-file in a XINCLUDE project. Before I explain a workaround, let's solve the second issue first.

The second issue is also linked the to the BODY element – in a different way, though. The situation – as I understand it – is that when you use XInclude, then the XML-preprosessor that Prince is using will smash — AKA "include" — all the linked files into one "body" before Prince goes over it. Therefore, links like your
<a href="C:\html\CONVENTIONS.html#Conventions">Conventions</a>
does not work, as the file "CONVENTIONS.html" is not part of the stuff that Prince gets to eat, from the point of view of Prince. (All in all, I think this is a feature/consequence of XInclude and not a Prince bug.)

The workaround/right way here is to skip the file path entirely and rely on project wide unique IDs (unique in the entire XInclude project). Then just use those IDs in the HREF of the A-element, without any file-path involved. So for example, the above example could be reworked to this:
<a href="#Conventions">Conventions</a>
(In my own project, I put ID-s on the BODY-elements of each of the included files, btw.)

The counter-reset issue again, seems unaffected by the XML-prepropesssing, however. Except that the counter-reset feature of Prince behaves as if there is only one BODY in the entire XINCLUDE-ed document — each time considering the BODY it stumbles upon as the scope.

Until the counter-reset behaviour starts taking into account documents with more than one BODY element, one can use this workaround, which I've tried myself:

My XINCLUDE-project had one "main" project file, which contained the TOC and <xi:include href="file" /> elements for all the files to be included in the project. Then, to get the enumeration to reset where I wanted, instead of relying on a ID between the BODY elements of the XI:INCLUDE-ed files, I made the counter-reset reset on an element which I placed in front of the respective <xi:include /> element in the "main" project file. Like this:
<xi:include href="file-second" />
<span id="first-counter-reset-here"></span><xi:include href="file-third" />

I think in your project, you will need to use this workaround in front of the <xi:include /> element which references the file "2 (different file again)" and the one referencing "3 (new file)". But not in front of the one referencing "2.4 (different file)" (as there is no problem with getting the counter to loop across files – it is only a problemt to get it to "reset across files".

Ok, I hope this helps. I did not have time to recheck everything I said here – I based it on a recent project experience, including glacing at the project files. If you still got troubles, I'll double check if there were something I forgot. :)

leif

david_baker
Thanks Leif - worked a charm.

I assume that the counter-reset issue will be fixed in a future version of Prince - the one looks like a bug. It seems I was trying to outsmart myself with the other one - trying to deal with XML namespaces where none were necessary.

:D
PDFWhiz
I have faced exactly the same two problems. I have sorted out the TOC one (thanks a lot) , but I am still struggling with resetting the heading counters.

I have included the following line in front of XInclude entry in my html file:

<span id="first-counter-reset-here"></span>


And I have added in my CSS file:

#first-counter-reset-here
{
counter-reset: section;
counter-reset: subsect;
}

The numbering I am getting is as follows:
1
1.1
1.1.1
1.1.2
.
.
.
2
2.2
2.2.3

Please let me know what I am missing to make this work correctly.
Thanks.
mikeday
Would you be able to email me (mikeday@yeslogic.com) a short sample document that demonstrates the problem?
kenshaw
I've got this same issue (counter-reset across files), and am trying to figure out a way around it. It's really frustrating, since I converted over to XHTML from DocBook.

Has there been any progress on this? I have a rather large document with a number of appendices and the nested counter reset is really a pain in the ass, especially since (one of) the document I'm working on specifically requires certain items to be numbered X.X.X.
mikeday
This issue may be fixed in Prince 8.0, now available in beta.