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.
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
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
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
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: 907
- 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
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