Pointing to a different SVG cover based on bookmap info
Having trouble installing Oxygen PDF Chemistry? Got a bug to report? Post it all here.
-
- Posts: 13
- Joined: Sat Jun 23, 2018 12:52 am
Pointing to a different SVG cover based on bookmap info
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:
I would need the image to change according to the bookmap. Possibly based on the product name (using prodinfo/prodname):
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
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;
}
Code: Select all
<bookmeta>
(...)
<prodinfo>
<prodname>NiceProduct</prodname>
</prodinfo>
Any ideas? Please let me know if this is unclear.
Thank you very much.
Louis
-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: Pointing to a different SVG cover based on bookmap info
The solution is to use an XPath to extract some information from the document, and based on it select the SVG images.
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
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'\
"));
}
Many regards,
Dan
-
- Posts: 13
- Joined: Sat Jun 23, 2018 12:52 am
Re: Pointing to a different SVG cover based on bookmap info
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
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
-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: Pointing to a different SVG cover based on bookmap info
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
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"));
}
-
- Posts: 922
- Joined: Thu May 02, 2019 2:32 pm
Re: Pointing to a different SVG cover based on bookmap info
Post by chrispitude »
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
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
-
- Posts: 30
- Joined: Thu Nov 30, 2023 12:45 pm
Re: Pointing to a different SVG cover based on bookmap info
Post by horisonten »
Based on this solution. Can anyone please tell me why the following is not working? It seems as if it doesn't check for the 'product' at all, and simply selects the last "else" = default picture.Dan wrote: ↑Fri Dec 18, 2020 12:12 pmCode: 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'\ ")); }
*[class ~= "front-page/front-page-title"]:after {
/*more stuff*/
background-image: url(oxy_xpath("\
if(//bookmap/@product[1] = 'product1') then 'resources/cover_images/product1.svg' else\
if(//bookmap/@product[1] = 'product2') then 'resources/cover_images/product2.svg'\
else 'resources/cover_images/replace_me.svg'\
"));
}
Last edited by horisonten on Tue May 28, 2024 9:25 am, edited 1 time in total.
-
- Posts: 665
- Joined: Wed Oct 16, 2019 3:47 pm
Re: Pointing to a different SVG cover based on bookmap info
Post by julien_lacour »
Hello,
The query isn't working because XPath expressions are applied on the merged.html file, not on the DITA source files and in HTML5 there's no <bookmap> element. The best practice is to match on the elements class attribute as it contains the original DITA class.
You can check this topic from our user guide for more information about how to use XPath expressions in CSS.
Regards,
Julien
The query isn't working because XPath expressions are applied on the merged.html file, not on the DITA source files and in HTML5 there's no <bookmap> element. The best practice is to match on the elements class attribute as it contains the original DITA class.
You can check this topic from our user guide for more information about how to use XPath expressions in CSS.
Regards,
Julien
-
- Posts: 30
- Joined: Thu Nov 30, 2023 12:45 pm
Re: Pointing to a different SVG cover based on bookmap info
Post by horisonten »
Thank you very much for pointing me in the right directionjulien_lacour wrote: ↑Tue May 28, 2024 12:07 pm Hello,
The query isn't working because XPath expressions are applied on the merged.html file, not on the DITA source files and in HTML5 there's no <bookmap> element. The best practice is to match on the elements class attribute as it contains the original DITA class.
You can check this topic from our user guide for more information about how to use XPath expressions in CSS.
Regards,
Julien

This gave me the results I was looking for:
Code: Select all
background-image: url(oxy_xpath("\
if(//*[contains(@class, ' map/map ')]/@product[1] = 'product1') then 'resources/cover_images/product1.svg' else\
if(//*[contains(@class, ' map/map ')]/@product[1] = 'product2') then 'resources/cover_images/product2.svg'\
else 'resources/cover_images/replace_me.svg'\
"));
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service