Pointing to a different SVG cover based on bookmap info

llpick
Posts: 11
Joined: Sat Jun 23, 2018 12:52 am

Pointing to a different SVG cover based on bookmap info

Post by llpick » Thu Dec 17, 2020 8:38 pm

Hi there,

I've been using PDF Chemistry using 1 CSS for each bookmap, which worked fine up to a point, but now I'd like to move to a single CSS.

The only problem so far has been the cover page.
The text displayed on the cover itself is lifted from the bookmap, so no problem there.
But the background image is an SVG file, linked as follows from the CSS file:

Code: Select all

@page front-page
 {
 
    background-image: url("img/front_back/front_cover.svg");
    background-repeat: no-repeat;
    background-size: 100%;
    margin-top: 10cm;
   
}
I would need the image to change according to the bookmap. Possibly based on the product name (using prodinfo/prodname):

Code: Select all

   <bookmeta>
(...)
       <prodinfo>
           <prodname>NiceProduct</prodname>
       </prodinfo>
But right now I have no clue as to how I can pass this info to the CSS from the bookmap...

Any ideas? Please let me know if this is unclear.
Thank you very much.

Louis

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

Re: Pointing to a different SVG cover based on bookmap info

Post by Dan » Fri Dec 18, 2020 12:12 pm

The solution is to use an XPath to extract some information from the document, and based on it select the SVG images.

Code: Select all

@page front-page {
    background-image: url(oxy_xpath("\
		if(//*[contains(@class, ' topic/prodname ')][1] = 'gardening') then 'bg-gardening.svg' else\
		if(//*[contains(@class, ' topic/prodname ')][1] = 'soil') then 'bg-soil.svg'\
		else 'bg-default.svg'\
    "));
}
The backslash is used to continue the expression string on following lines (there should be no spaces after it). For more use cases solved using XPath see: https://www.oxygenxml.com/doc/versions/ ... aid-title6

Many regards,
Dan

llpick
Posts: 11
Joined: Sat Jun 23, 2018 12:52 am

Re: Pointing to a different SVG cover based on bookmap info

Post by llpick » Fri Dec 18, 2020 2:19 pm

Thank you Dan, this works perfectly like this.

To go a bit further: do you see any way of passing the xpath to the svg file name?
It would remove the need to add as many "if" statements as there are covers, and to update the CSS every time a new product/cover is added.

Many thanks.
Louis

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

Re: Pointing to a different SVG cover based on bookmap info

Post by Dan » Fri Dec 18, 2020 7:23 pm

Sure, you can set the name of the image file in the metadata section, in a data element (you can put one in the prodname element for instance, or in a topic), then use XPath to extract it and pass it to the CSS url function. In the next example the name attribute of the data element is set to 'image-file-name', but you can use anything as long as you match it correctly in the XPath expression.

For more information:
https://www.oxygenxml.com/doc/versions/ ... aid-title3

Code: Select all

<map>
	<title>Growing Flowers</title>
	<topicmeta>		
		<prodinfo>
			<prodname><data name="image-file-name" value="bg-1.svg"></data>gardening</prodname>		
		</prodinfo>		
	</topicmeta>
	...

Code: Select all

@page front-page {
    background-image: url(oxy_xpath("//*[contains(@class, ' topic/data')][@name='image-file-name'][1]/@value"));
}


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

Re: Pointing to a different SVG cover based on bookmap info

Post by chrispitude » Mon Dec 21, 2020 4:40 pm

Hi Louis,

If you have a small number of book categories, consider setting the @outputclass attribute on your top-level map element, then include this map element in your CSS selector path.

We have books, release notes, and product installation notes. Their cover pages and their headers/footers vary a bit. We have a map @outputclass value for each one, then we vary things in the CSS accordingly.

For details, see:

post58653.html?hilit=conditional%20outputclass#p58653

llpick
Posts: 11
Joined: Sat Jun 23, 2018 12:52 am

Re: Pointing to a different SVG cover based on bookmap info

Post by llpick » Wed Jan 06, 2021 11:03 am

Dear Chris and Dan, thank you both for your detailed answers.
Lots to chew on, and definitely more flexibility than I expected.

Post Reply