oxy_* functions and maptitle variable not working in CSS @page scope?

Post here questions and problems related to editing and publishing DITA content.
Vinny
Posts: 30
Joined: Wed Jan 12, 2022 1:07 pm

oxy_* functions and maptitle variable not working in CSS @page scope?

Post by Vinny »

Folks,
I’m trying to split the ‘Title’ of a document to have it printed on two lines in the footer (PDF/CSS transform). For example, my title could be ‘Sample Document $ Rev. 1' and in the footer I'd like to have 'Sample Document' printed above 'Rev. 1', using '$' as a separator for the two lines.
So I set out writing a first CSS draft rule like this:

Code: Select all

@page :right {
	[…]
	@bottom-right {
       		content: oxy_substring(string(maptitle), 0, oxy_indexof(string(maptitle), "$"));
       	}
}
This would of course display only the first part, but, the result is stubbornly void. This doesn’t return anything, although the ‘maptitle’ variable is correctly set, since:

Code: Select all

	content: string(maptitle);
works perfectly well.
Also, this code:

Code: Select all

	content: oxy_indexof(string(maptitle),"$");
displays '-1' in the footer, as if the string was empty or not defined. I've tried other characters instead of '$', to no avail.
However,

Code: Select all

	content: oxy_indexof("abc@abc", "@");
Correctly outputs 3. So something is wrong, as if maptitle wasn't set when the CSS rule is evaluated.
Any clue to what I did wrong or workaround?

EDIT: This works fine, is maybe simpler?

Code: Select all

       content: oxy_xpath('substring-before(//head/title/text(), "|")')
                 "\0A"
                 oxy_xpath('substring-after(//head/title/text(), "|")');
julien_lacour
Posts: 742
Joined: Wed Oct 16, 2019 3:47 pm

Re: oxy_* functions and maptitle variable not working in CSS @page scope?

Post by julien_lacour »

Hello,

The issue is that string() CSS function is evaluated per page for margin boxes, so its value is only available at page generation time and cannot be used as a parameter in an oxy function.
Instead you could use oxy_xpath() and create a new string-set (keep the original maptitle or it will be overriden by the custom definition):

Code: Select all

*[class ~= "front-page/front-page-title"] > *[class ~= "topic/title"] {
  string-set: maptitle content(), 
custommaptitle oxy_xpath("if (contains(text(), '$')) then replace(text(), '\\$', '\0A') else text()");
}
@page :right {
  @bottom-right {
    content: string(custommaptitle);
  }
}

Regards,
Julien
Post Reply