Forum How do I...?

Support for XML cross-references

gareth
I think I'm missing something but cannot seem to get XML xrefs working. Consider:
<toc-entry>
    <label>1.2.3</label>
    <title>Sample TOC entry</title>
    <nav-pointer rid="sec_1.2.3"/>
</toc-entry>

I need nav-pointer to output the page reference. So, within the CSS for nav-pointer, I'm using
target-counter(attr(rid), page)
but it doesn't resolve the page counter. If I update my @rid attribute to add the leading hash mark (e.g., rid="#sec_1.2.3") then it does work, as @rid is now a URL fragment.


Unfortunately, if I add the hash mark to the XML attributes, then the XML is invalid. I tried CSS variables but var() doesn't seem to work within target-counter, so I'm out of ideas. What is best practice please?
David J Prokopetz
If no other solution suggests itself, you could append a small Javascript when processing the XML file with Prince to tweak its contents into something Prince understands (in this case, to insert the hash mark into the rid attribute). Perhaps something like this:

let navPointers = document.querySelectorAll('nav-pointer');
for (let i = 0; i < navPointers.length; i++) {
    navPointers[i].setAttribute('rid', '#' + navPointers[i].getAttribute('rid'));
}


(If you're using Prince from the command line, an external Javascript file can be included using the --script argument.)
gareth
Thanks David, that is a great suggestion and pre-processing is something I'm already doing with these files with XSLT. The use of Javascript means I don't have to make the XML invalid prior to publishing.
I will see if anyone else has any tips or advice on best practice. I had assumed XML xref handling would be a core product capability, but this option works just fine.