Is it possible to access map variables from Customization CSS?

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
antoterrence
Posts: 28
Joined: Sat May 04, 2019 5:55 pm

Is it possible to access map variables from Customization CSS?

Post by antoterrence » Wed Aug 21, 2019 7:51 pm

We are planning to create Publishing Template using Customization CSS.
For simple maps, the following page says we can add copyright info using CSS selectors:
https://www.oxygenxml.com/doc/versions/ ... aid-title9

Problem 1:
But it does not create a copyright page after the cover page when publishing a simple map.

Problem 2:
Is it possible to access KEY DEFINITIONS through the Customization CSS?

Dan
Posts: 416
Joined: Mon Feb 03, 2003 10:56 am

Re: Is it possible to access map variables from Customization CSS?

Post by Dan » Thu Aug 22, 2019 1:12 pm

Hello,


Regarding the first issue:

The documentation was a bit outdated, thank you for reporting the problem!
That topic was referring only to the direct transformation, not to the one based on HTML5. I changed the samples, the documentation will be updated soon.
Until that, please used the following CSS selector:

Code: Select all

*[class ~= "front-page/front-page"] { ... 
instead of

Code: Select all

front-page{ ... 
The examples from that documentation topic are replaced by:

Code: Select all

*[class ~= "front-page/front-page"]:after {

	display: block;

	page: copyright-notice-page; /* Moves the synthetic element on a new page. */

	margin-top: 90%; /* use margins to position the text in the page */
	margin-left: 5em;
	margin-right: 5em;

	content: "Copyright 2018-2019 MyCorp Inc. \A All rights reserved";

	text-align: center; /* More styling */
	color: blue;
}

*[class ~= "front-page/front-page"]:after(2) {
	display: block;
	page: copyright-notice-page; /* Continue on the same page as the first ':after'. */
	content: "Some more styled text";
	color: red;
}

*[class ~= "front-page/front-page"]:after(3) {
	display: block;
	page: copyright-notice-page;
	content: 
	"Year: " 
		oxy_xpath('//*[contains(@class, " front-page/front-page ")]/*[contains(@class, " map/topicmeta ")]/*[contains(@class, " topic/copyright ")]/*[contains(@class, " topic/copyryear ")]/@year') 
	"\A Holder: " 
		oxy_xpath('//*[contains(@class, " front-page/front-page ")]/*[contains(@class, " map/topicmeta ")]/*[contains(@class, " topic/copyright ")]/*[contains(@class, " topic/copyrholder ")]/text()');
	color: green;
}

@page copyright-notice-page {
	@top-left {
		content: none; /* Clear the headers for the copyright page */
	}
	@top-right {
		content: none;
	}
}
Regarding the second isssue:

All the keys are expanded before the CSS is applied.
In the output folder you will find two .merged files, you can use them to inspect how the keys were expanded. The keyref attributes remains on the topics that receive the expanded content, so you could use it to find out the expanded key. Can you explain more about the problems you encounter? For example are there key values that do not appear in output? Do you need to style the content depending on the key?


Many regards,
Dan

antoterrence
Posts: 28
Joined: Sat May 04, 2019 5:55 pm

Re: Is it possible to access map variables from Customization CSS?

Post by antoterrence » Thu Sep 12, 2019 10:11 pm

Thank you. I am now able to construct the copyright content dynamically.

Code: Select all

*[class ~= "front-page/front-page"]:after(2) {
	display: block;
	page: copyright-notice-page; /* Continue on the same page as the first ':after'. */
	content: "some legal text";
}

*[class ~= "front-page/front-page"]:after(3) {
	display: block;
	page: copyright-notice-page;
	content: "©"
		oxy_xpath('//*[contains(@class, " bookmap/copyrfirst")]/*[contains(@class, " bookmap/year")]/text()') 
	"-" 
		/* oxy_xpath('//*[contains(@class, " bookmap/copyrlast")]/*[contains(@class, " bookmap/year")]/text()')  */
	oxy_xpath("format-date(current-date(), '[Y0001]')")
	" Company name. All Rights Reserved. "
	 
	 oxy_xpath('//*[contains(@class, "topic/ph")][@keyref="patents"]/text()')
}

*[class ~= "front-page/front-page"]:after(4) {
	display: block;
	page: copyright-notice-page;
	content: "sometext attribution"
	 
	 oxy_xpath('//*[contains(@class, "topic/ph")][@keyref="trademarks"]/text()')
	 
	 " general attribution"
}
QUESTION
Is it a good practice to construct the entire copyright content this way instead of using a topic under legal notice element? The CSS approach works better for me because I can add the current year dynamically without expecting the writer to set the year using the copyrlast element or a key. Writers do not have to worry about adding a legal notice topic to their books.

Dan
Posts: 416
Joined: Mon Feb 03, 2003 10:56 am

Re: Is it possible to access map variables from Customization CSS?

Post by Dan » Mon Sep 16, 2019 9:43 am

If this simplifies the work for your writers, I think you should go on with this CSS+XPath approach. However, if you plan to publish this to other formats, like WebHelp or plain HTML, you will not benefit of this customization, so please take care.
Many regards,
Dan

antoterrence
Posts: 28
Joined: Sat May 04, 2019 5:55 pm

Re: Is it possible to access map variables from Customization CSS?

Post by antoterrence » Tue Sep 17, 2019 12:25 pm

Dan wrote:
Mon Sep 16, 2019 9:43 am
If this simplifies the work for your writers, I think you should go on with this CSS+XPath approach. However, if you plan to publish this to other formats, like WebHelp or plain HTML, you will not benefit of this customization, so please take care.
Many regards,
Dan
Thank you, Dan. I kind of figured out the same. We want to single-source as much as possible. However, this customization option is not available for other transforms. The advantage with adding a topic/page dynamically is that you don't have to include such standards components as Legal Notice, Copyright page etc as part of the bookmap template. Writers do not have to manually reference them in their guides. Since this approach does not scale for all outputs, I kind of stopped pursuing it.
By the way, the keys are not available in the merged html file unless they are referenced in the content. That does not scale either for the kind of approach I tried taking.

Dan
Posts: 416
Joined: Mon Feb 03, 2003 10:56 am

Re: Is it possible to access map variables from Customization CSS?

Post by Dan » Wed Sep 18, 2019 3:45 pm

Maybe you can use some XSLT extensions for the webhelp. Please see an example here:

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

The full customization manual is here:

https://www.oxygenxml.com/doc/versions/ ... -tips.html

Many regards,
Dan

chrispitude
Posts: 57
Joined: Thu May 02, 2019 2:32 pm

Re: Is it possible to access map variables from Customization CSS?

Post by chrispitude » Wed Oct 02, 2019 5:25 pm

Regarding the second question, I had a similar question about accessing keydef values from CSS here:

post54203.html#p54203

In my case, the keys would be defined in the topic map *but* never referenced (except by the CSS), so there was no expansion in the content that I could search for. So, I'm still using <bookmeta>, but I dislike how duplicative and wasteful it is during processing for the small amount of information it provides.

It would be nice if there were a way to somehow store all keydefs in a nonprinting way somewhere in the merged XML file for reference. (Could a DITA plugin do this?)

Dan
Posts: 416
Joined: Mon Feb 03, 2003 10:56 am

Re: Is it possible to access map variables from Customization CSS?

Post by Dan » Fri Oct 04, 2019 10:07 am

The main condition is to have this key referenced from the content (either topic or map).

If you do not have it referenced, you may force a reference by using the topicmeta or bookmeta section of your map and a data element. This has no effect on the published content, but allows the CSS rules to use its content. (There are maps that define thousands of keys, and automatically copying them in the merged map is not practical.)

Code: Select all

  <bookmeta>
    ....
    <data keyref="my_key"/>
    ....
  </bookmeta>
This is expanded in the merged HTML file to:

Code: Select all

<div class="- map/topicmeta bookmap/bookmeta topicmeta bookmeta">
	...
	<div keyref="my_key" class="- topic/data data">
		<div class="- topic/keyword keyword">KEY VALUE</div>
	</div>
	...
</div>
Let's consider we need the key expanded value in the footer of the publication. You can define a string-set on this data element:

Code: Select all

*[class ~= "topic/data"][keyref="my_key"] {
	string-set: key-string content(text);
}
@page {	
	@bottom-left {
		content: "My key is: " string(key-string) !important;		
	}
}
Or you can use the value from a :before pseudo element, like the one for the title:

Code: Select all

*[class ~= "topic/title"]:before {
	content: oxy_xpath("//*[contains(@class, 'topic/data')][@keyref = 'my_key']//text()");
}
Another use-case is to use the key as a source for a custom PDF document property:

Code: Select all

*[class ~= "topic/data"][keyref="my_key"] {
	-oxy-pdf-meta-custom: attr(keyref) content(text);
}
Let us know if you need more details,
Many regards,
Dan

Post Reply