Duplicate Title Names on Cover Page in PDF Output

Post here questions and problems related to editing and publishing DITA content.
Tinmen
Posts: 21
Joined: Wed Jun 28, 2023 11:49 pm

Duplicate Title Names on Cover Page in PDF Output

Post by Tinmen »

This displays the content correctly:

Code: Select all

*[class ~= "bookmap/booktitle"]:after(4) {
    display: block;
    content: oxy_xpath('if(//*[contains(@class, " bookmap/booknumber ")]) then concat(" Version ", //*[contains(@class, " bookmap/booknumber ")]/text()) else ""'); 
    text-align: center;
    color: black;
    font-size: .5em;
    font-style: italic;
}
Content appears on the cover page as it should.

For example: Version 2023.5.0.7

This does not display any content on the cover page:

Code: Select all

*[class ~= "bookmap/booktitle"]:after(3) {
display: block;
content: oxy_xpath('if(//*[contains(@class, " bookmap/mainbooktitle ")]) then concat(", Title ", //*[contains(@class, " bookmap/mainbooktitle ")]/text()) else ""');
color: red;  
font-size: .5em;
}
and fails with the following Oxygen message:
[CH] jar:file:/C:/Program%20Files/Oxygen%20XML%20Editor%2024/lib/oxygen-pdf-chemistry.jar!/chemistry-default.css XPath "if(//*[contains(@class, " bookmap/mainbooktitle ")]) then concat(", Title ", //*[contains(@class, " bookmap/mainbooktitle ")]/text()) else """ failed: XPath failed due to: A sequence of more than one item is not allowed as the second argument of fn:concat() (text{Deployment Guide}, text{Deployment Guide})
Substituting string-join in place of concat works as in:

Code: Select all

*[class ~= "bookmap/booktitle"]:after(3) {
display: block;
content: oxy_xpath('if(//*[contains(@class, " bookmap/mainbooktitle ")]) then string-join(//*[contains(@class, " bookmap/mainbooktitle ")]/text()) else ""');
color: red;  
font-size: .5em;
}
and it generates the output on the cover page, but the main book title appears twice as in:
Deployment GuideDeployment Guide
This only appears to happen with anything in the book title tags. <mainbooktitle> and <booktitlealt> do the same thing. Using concat creates an error while string-join works, but the contents appear twice and are jammed together.

Any ideas as to what I am doing wrong?
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Duplicate Title Names on Cover Page in PDF Output

Post by chrispitude »

Hi Tinmen,

Somehow I think your XPath expression is picking up multiple <mainbooktitle> elements. If you look in the merged HTML file produced by PDF Chemistry, do you see multiple such elements?

I tried a simple testcase with your CSS and I do not get a duplicated title:

test_bookmap_with_css.zip
(2.5 KiB) Downloaded 31 times

You might be able to do something like this to use only the first element:

Code: Select all

oxy_xpath('if(//*[contains(@class, " bookmap/mainbooktitle ")]) then (//*[contains(@class, " bookmap/mainbooktitle ")])[1] else ""');
but it would be good to understand where the extra element is coming from. Maybe there's a submap in your book or something like that.

In my suggested XPath above, note that I did not limit the path to text() nodes. This is because there could be elements that contain text within them, so I relied on XPath to evaluate the element and its descendants to text for me (which is the default behavior when evaluating an element's value).
Tinmen
Posts: 21
Joined: Wed Jun 28, 2023 11:49 pm

Re: Duplicate Title Names on Cover Page in PDF Output

Post by Tinmen »

Thanks for taking the time to reply. I haven't evaluated the HTML output as yet since I only needed a PDF output. However, I will do so to see what happens.

I used your code snippet, and the PDF cover now renders as:
<span class="- topic/ph bookmap/mainbooktitle ph mainbooktitle">Deployment Guide</span>
So no duplication as I was seeing with my code.

So, I updated the code line to read:

Code: Select all

oxy_xpath('if(//*[contains(@class, " bookmap/mainbooktitle ")]) then (//*[contains(@class, " bookmap/mainbooktitle ")])[1]//text() else ""');
and it renders perfectly now.

Thank you!
Last edited by Tinmen on Thu Jun 29, 2023 9:58 pm, edited 2 times in total.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Duplicate Title Names on Cover Page in PDF Output

Post by chrispitude »

Hi Tinmen,

I'm glad you got it working!

My reference to the merged HTML file was not to an HTML transformation, but rather to the PDF transformation you are already running. When you run a PDF Chemistry transformation, you should get a .merged.html file in the working directory as described here:

https://www.oxygenxml.com/doc/versions/ ... erged.html

This is the intermediate file that the XPath in your CSS property is operating on. You can look in this file and see if there are two <mainbooktitle> elements. Their locations should help explain why it is happening.
Tinmen
Posts: 21
Joined: Wed Jun 28, 2023 11:49 pm

Re: Duplicate Title Names on Cover Page in PDF Output

Post by Tinmen »

Ok, thank you for the clarification. I will check that file.

Your help is very much appreciated!

Tinmen
Post Reply