Custom transformation parameters for css (background image for the title page)

Post here questions and problems related to editing and publishing DITA content.
jdonges
Posts: 8
Joined: Mon Dec 16, 2019 3:01 pm

Custom transformation parameters for css (background image for the title page)

Post by jdonges »

Hello, I need some help again.

I use the XSLT and CSS to PDF Transformation Scenario and have specified a background image for the title page

Code: Select all

@page front-page{
    
    background-image: url("../img/title.png");
}
It works fine as long as we need the same title page all the time. But to produce different documents with different titlepages I would like to pass the url to an image as parameter to the transformation.

I tried to make a new parameter "titlepage" in the transformation settings and refer to it with

Code: Select all

@page front-page{
    
    background-image: url(${titlepage});
}
But this does not work.
How can we pass the filename to transformation?
tia
Jörn
julien_lacour
Posts: 496
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom transformation parameters for css

Post by julien_lacour »

Hello,

The best thing to do is to use a custom parameter:
  1. In the transformation scenario dialog, create a new parameter called for example "args.css.param.cover-page" and set its value to the image path (for example: "../img/title.png")
  2. In your CSS file use the following selector

    Code: Select all

    @page front-page {
        background-image: url(oxy_xpath('/*/@*[local-name()="cover-page"][1]'));
    }
You image should appear in the PDF.

Regards,
Julien
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Custom transformation parameters for css

Post by Dan »

Please note that the image path should be given as an absolute URI, like: file:/C:/temp/example.svg. It works also with relative paths, but it will solve them relative to the XML location.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: Custom transformation parameters for css

Post by chrispitude »

Useful technique, thank you!

Is there a way to write a CSS selector so that it is only applied when the parameter is set to a particular value?
julien_lacour
Posts: 496
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom transformation parameters for css

Post by julien_lacour »

Hello,

It is possible to control the first parameter by using a second custom parameter, for example "args.css.param.use-cover" with value "yes".

Then in the CSS, using the following selectors:

Code: Select all

:root[use-cover='yes'] *[class~='front-page/front-page'] {
    page: custom-front-page;
}

@page custom-front-page {
	background-image: url(oxy_xpath('/*/@*[local-name()="cover-page"][1]'));
}
Regards,
Julien
jdonges
Posts: 8
Joined: Mon Dec 16, 2019 3:01 pm

Re: Custom transformation parameters for css

Post by jdonges »

This works well, thank you!
Sometimes it is hard to figure out these cryptic notations :)

We have to use the relative paths because the XML data is in a repository and will be downloaded to different locations.

Regards
Joern
Post Reply