Output PDF file name based on variables

Post here questions and problems related to editing and publishing DITA content.
oxygen-user
Posts: 9
Joined: Wed Jan 24, 2024 4:36 pm

Output PDF file name based on variables

Post by oxygen-user »

Hi,
How can I make sure the PDF output file name is based on the DITA bookmap title (or certain keywords)?

I tested various methods but none of them worked.

Best wishes.

Code: Select all

<!-- Overwrite file name, See
https://www.oxygenxml.com/doc/versions/26.1/ug-pdf-css/topics/dcpp_parameters.html?hl=args.output.base
https://www.oxygenxml.com/doc/versions/26.0/ug-editor/topics/editor-variables.html?hl=xpath_eval

https://www.oxygenxml.com/forum/post71459.html#p71459 
https://www.oxygenxml.com/forum/post54730.html#p54730 
 -->

<!--with rootmapURL https://www.oxygenxml.com/doc/versions/26.1/ug-editor/topics/editor-variables.html     -->

<!--Transformation fails  -->
<!-- <parameter name="args.output.base" value="${xpath_eval(doc('${rootMapURL}')//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2])}"/> -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2])}"/> -->

<!-- static -->
<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'topic/title')]//text())))}"/> -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'map/map')]/*[contains(@class, 'front-page/front-page-title')]//text())))}"/> -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'map/map')]/*[contains(@class, 'topic/title')]//text())))}"/> -->

<!-- file name is identical to value -->
<!--<parameter name="args.output.base" value="${xpath_eval(upper-case(substring('${cfn}', 1, 4)))}"/>-->
	 
<!-- dynamic -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${ask('Set new ID attribute', generic, '${xpath_eval(normalize-space(string-join(/*[contains(@class, 'front-page/front-page-title')]//text())))}"/> -->

<!-- <parameter name="args.output.base" value="${ask('Set new ID attribute', generic, '${xpath_eval(//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2]}')}"/> -->

<!-- file name is identical to value -->
<!-- <parameter name="args.output.base" value="${ask('Message', input_type, '${cfn}')}"/> -->
xephon
Posts: 146
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Output PDF file name based on variables

Post by xephon »

I'd recommend to read the metadata from your map after preprocessing (after keyrefs are resolved) and then do the renaming in a new Ant target at the end of the processing.
stefan-jung.org – Your DITA/DITA-OT XML consultant
julien_lacour
Posts: 559
Joined: Wed Oct 16, 2019 3:47 pm

Re: Output PDF file name based on variables

Post by julien_lacour »

Hello,

You cannot use rootmapURL editor variable in args.output.base value, only the following ones:
image.png
image.png (55.82 KiB) Viewed 749 times
If you still cannot make the transformation succeeds, could you copy the failure stacktrace here?

Regards,
Julien
oxygen-user
Posts: 9
Joined: Wed Jan 24, 2024 4:36 pm

Re: Output PDF file name based on variables

Post by oxygen-user »

Hi,
Sorry for not getting back to you earlier.

I just get quite a generic error message.

Code: Select all

System ID: C:\Users\...\Desktop\....ditamap
Scenario: DITA Map PDF - based on HTML5 & CSS (...)
Input file: C:\Users\...\Desktop\....ditamap
Engine name: DITA-OT
Severity: fatal
Description: Transformation failed.

I tested the following parameters individually but all of them failed:

Code: Select all

<!-- Overwrite file name, See
https://www.oxygenxml.com/doc/versions/26.1/ug-pdf-css/topics/dcpp_parameters.html?hl=args.output.base
https://www.oxygenxml.com/doc/versions/26.0/ug-editor/topics/editor-variables.html?hl=xpath_eval

https://www.oxygenxml.com/forum/post71459.html#p71459 
https://www.oxygenxml.com/forum/post54730.html#p54730 
 -->

 <!--with rootmapURL https://www.oxygenxml.com/doc/versions/26.1/ug-editor/topics/editor-variables.html     -->

 <!--Transformation fails  -->
<!-- <parameter name="args.output.base" value="${xpath_eval(doc('${rootMapURL}')//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2])}"/> -->


<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2])}"/> -->
<!--<parameter name="args.output.base" value="${xpath_eval(//*[contains(@class, 'topic/category')])}"/>-->


<!-- static -->
<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'topic/title')]//text())))}"/> -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'map/map')]/*[contains(@class, 'front-page/front-page-title')]//text())))}"/> -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(/*[contains(@class, 'map/map')]/*[contains(@class, 'topic/title')]//text())))}"/> -->

<!-- file name is identical to value -->
<!--<parameter name="args.output.base" value="${xpath_eval(upper-case(substring('${cfn}', 1, 4)))}"/>-->

<!-- <parameter name="args.output.base" value="${xpath_eval(normalize-space(string-join(//*[contains(@class, "front-page/front-page")]/*[contains(@class, "map/topicmeta")]/*[contains(@class, "topic/category")]/*[contains(@class, "topic/keyword")]/text())))}"/> -->


<!-- dynamic -->

<!-- Transformation fails -->
<!-- <parameter name="args.output.base" value="${ask('Set new ID attribute', generic, '${xpath_eval(normalize-space(string-join(/*[contains(@class, 'front-page/front-page-title')]//text())))}"/> -->

<!-- <parameter name="args.output.base" value="${ask('Set new ID attribute', generic, '${xpath_eval(//*[contains (@class, " front-page/front-page-title")]/*[contains(@class, " topic/title ")]/*[contains(@class, " topic/keyword ")][2]}')}"/> -->

<!-- file name is identical to value -->
<!-- <parameter name="args.output.base" value="${ask('Message', input_type, '${cfn}')}"/> -->
Do you know what else I could try?
julien_lacour
Posts: 559
Joined: Wed Oct 16, 2019 3:47 pm

Re: Output PDF file name based on variables

Post by julien_lacour »

Hello,

I forget to mention that you can't use editor variables when you set the args.output.base parameter outside of Oxygen so ${xpath_eval(expression)} will not expand in command line or inside a publishing template descriptor (in <parameter/>).

Sorry for the misleading.

Regards,
Julien
chrispitude
Posts: 915
Joined: Thu May 02, 2019 2:32 pm

Re: Output PDF file name based on variables

Post by chrispitude »

Hi oxygen-user,

We have a similar situation. Our PDFs are named as follows:
  • For maps that are published in a single configuration, we want the PDF to be named using the map.
  • For maps that are published in multiple configurations via DITAVAL, we want the PDF to be named using the keyscope.
All our bookmaps (which correspond to our PDF "books") are referenced in a top-level WebHelp OLH ditamap. I wrote a refactoring operation to convert this OLH ditamap to DITA-OT project, files, where:
  • A single WebHelp deliverable is created for the entire OLH ditamap
  • A PDF deliverable is created for each bookmap reference in the OLH ditamap, with the args.output.base parameter determined using the rules above
This method has worked wonderfully for us. Writers simply edit the WebHelp ditamap to include/exclude/name whatever books they want, and everything else just follows along.

If you are interested, I could write an Oxygen XML blog post that explains how to do it.
Post Reply