PDF output of prolog author after topic body

Post here questions and problems related to editing and publishing DITA content.
waltscheper
Posts: 1
Joined: Mon Jul 17, 2023 2:28 am

PDF output of prolog author after topic body

Post by waltscheper »

Background:
I'm 60 days into DITA and have constructed a family story book. I have topics for short stories/events of various family members. These have been provided to me by my cousins and I want to print the contributor for each topic in the PDF. (Later this may go to another format as I have an AWS Apache server configured for the family url). I have a custom plugin directory based on DITA PDF - based on HTML5 & CSS.

Ask:
I haven't been able to print author accurately in each topic. Using various ideas from the forum I've gotten a single topic to work using oxy_xpath but as soon as I work with the full map I get a concatenation of every topic's author. I've concluded using oxy_xpath may not be a solution. I suspect it is not executing in state with the processing of the topics but rather outside topic processing and there isn't an obvious way to pass the single topic for which I want the author. To say the least I'm confused even after reading numerous manuals, forum solutions and webinars.

For reference here is the errant oxy_xpath which returns all topic authors: oxy_xpath("//*[contains(@class, 'topic/author')][1]/text() ");
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: PDF output of prolog author after topic body

Post by julien_lacour »

Hello,

Instead of using the oxy_xpath() function you should try to create a string-set, like in this example:

Code: Select all

@page {
  @bottom-left {
    content: "Author: " string(author);
  }
}

*[class ~= "topic/author"] {
  string-set: author content();
}
The string-set will be updated for each new author and displayed in the page footer.

Regards,
Julien
waltscheper
Posts: 1
Joined: Mon Jul 17, 2023 2:28 am

Re: PDF output of prolog author after topic body

Post by waltscheper »

Julien thank you for the suggestion. I added both to my FSBMeta.css which is the last item in <resources> of my customize .opt for the template.

(Please forgive any newbie formatting errors in this post. Suggestions welcome.)

On Apply I'm getting the label "Author" but not the text from "topic/author".
This is the code from FSBMeta.css which has the original with xpath and the new with string-set:

Code: Select all

    *[class ~= "topic/body"]:after {
        margin: 1em;
        font-family: 'Arial ';
        font-weight: 500;
        font-size:.75em;
        content: "    Contributing Author:  "  oxy_xpath("//*[contains(@class, 'topic/author')][1]/text() "); ;
        
    }
 
*[class ~= "topic/author"] {
  string-set: author content();
}

@page {
  @bottom-left {
    content: "Author: " string(author);
  }
}

This is the topic I'm using to test before moving to the map:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="topic_z2t_pmp_twb">
    <title>Frederick's Arrival in NYC 1883</title>
    <prolog>
        <author type="contributor">Agnes Curry Scheper</author>
        <author type="contributor">Walter Frederick Scheper Jr</author>
        <critdates>
            <created date="2023-01-13"/>
        </critdates>  
        <metadata>
            <audience type="DorotheaScheper"/>
            <audience type="GraceScheper"/>
            <audience type="WalterScheper"/>
            <audience type="FrankScheper"/>
        </metadata>
        
    </prolog>
    <body>
        <p>Frederick most likely arrived in NYC on June 5, 1883. He is listed as Friedr Scheper on
            the Main. The Main is a sister ship of the Sailer and Donau. Frederick's sister Helene
            arrived in NYC nine months earlier on the Sailer. Agnes related a story of Frederick's
            arrival. He was mugged on arrival. All of his possessions and money were stolen. He was
            left indigent and alone. Frederick had been sleeping on the streets of NYC and one
            evening, to get out of the weather, he found a business doorway in which to sleep. This
            was a fortunate choice for Frederick. The doorway was to Richard Ahrens' Bar. Richard
            too had immigrated from Germany. Richard understood young Fred's plight and proposed an
            offer: <i><b>If Frederick would keep the bar clean by sweeping and mopping it he would have a room
                to sleep and food to eat.</b></i> Frederick was more than glad to have a safe
            place to rest. This was the beginning of a life long friendship with Richard and the
            Ahrens family. </p>
    </body>

</topic>

On Apply of Transformation to this single topic this is the output PDF that is now attached.
PDF Output from Apply.png
PDF Output from Apply.png (179.44 KiB) Viewed 415 times
Last edited by waltscheper on Wed Jul 19, 2023 5:52 pm, edited 1 time in total.
julien_lacour
Posts: 498
Joined: Wed Oct 16, 2019 3:47 pm

Re: PDF output of prolog author after topic body

Post by julien_lacour »

Hello,

In this case you can directly use the following rule and remove the string-set/string rules I gave you earlier:

Code: Select all

*[class ~= "topic/body"]:after {
  margin: 1em;
  font-family: 'Arial ';
  font-weight: 500;
  font-size: .75em;
  content: "    Contributing Author:  " oxy_xpath("string-join(ancestor::*[contains(@class, 'topic/topic')]//*[contains(@class, 'topic/author')]/text(), ' and ')");
}
Basically as this rule will apply on element with topic/body class, you just need your query to position onto the ancestor topic then search for all the authors for the current topic.
The string-join() function will further merge all the results the query will return and separate each result by " and ".

Regards,
Julien
Post Reply