Ways to store CSS-accessible book metadata besides <bookmeta>?

chrispitude
Posts: 66
Joined: Thu May 02, 2019 2:32 pm

Ways to store CSS-accessible book metadata besides <bookmeta>?

Post by chrispitude » Wed Jun 05, 2019 7:34 pm

We store metadata about our book in a <bookmeta> element in the top-level bookmap file, like this:

Code: Select all

<bookmap>
  <title>Our Product User Guide</title>
  <bookmeta>
    <author>chrispy</author>
    <publisherinformation>
      <organization>My Company, Inc.</organization>
      <printlocation>Mountain View, CA</printlocation>
      <published>
        <publishtype value="general"/>
        <completed>
          <year>2019</year>
          <month>June</month>
        </completed>
      </published>
    </publisherinformation>
    <prodinfo>
      <prodname>My Product</prodname>
    </prodinfo>
    <bookid>
      <edition>My Version</edition>
    </bookid>
  </bookmeta>
Then I reference this metadata in our PDF Chemistry CSS via oxy_xpath() to populate the cover page and headers/footers, like this:

Code: Select all

*[class~="front-page/front-page-title"]::after(2) {
    content: "Version " oxy_xpath('//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/edition ")]/text()') ", "
             oxy_xpath('//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/completed ")]/div[contains(@class, " bookmap/month ")]/text()') " "
             oxy_xpath('//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/completed ")]/div[contains(@class, " bookmap/year ")]/text()');
}

@page {
    @bottom-left {
      content: string(maptitle) "\a" oxy_xpath('//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/edition ")]/text()');
    }
}
and this works exactly as expected.

But in the merged XML file created by PDF Chemistry, the book metadata is propagated (duplicated!) in every single topic in the book. This metadata cascade is described as a requirement in the DITA spec (https://docs.oasis-open.org/dita/v1.2/o ... tamap.html), but it contributes to a significant size increase in the merged XML file:

book_without_meta.xml: 4,794,623 bytes
book_with_meta.xml: 5,285,917 bytes

Half a megabyte of text overhead to store a handful of text strings is too much for my comfort, even for a temporary file.

I tried defining some key values in the top-level bookmap:

Code: Select all

  <keydef keys="version">
    <topicmeta>
      <keywords>
        <keyword>P-2019.03-SP2</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="date">
    <topicmeta>
      <keywords>
        <keyword>June 2019</keyword>
      </keywords>
    </topicmeta>
  </keydef>
but they don't get replicated in the merged XML file for me to access via oxy_xpath().

Is there another way to store and maintain book information that can be accessed from CSS? Or is there a way to disable this book metadata propagation in a transform?

Thanks!

- Chris

Costin
Posts: 621
Joined: Mon Dec 05, 2011 6:04 pm

Re: Ways to store CSS-accessible book metadata besides <bookmeta>?

Post by Costin » Fri Jun 07, 2019 3:06 pm

Hi Chris,

There are two solutions for that:

- either select only the 1st instance of the content returned by the XPath, encapsulating each of your path expressions in parentheses (), followed by [1], like:

Code: Select all

*[class~="front-page/front-page-title"]::after(2) {
    content: "Version " oxy_xpath('(//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/edition ")]/text())[1]') ", "
             oxy_xpath('(//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/completed ")]/div[contains(@class, " bookmap/month ")]/text())[1]') " "
             oxy_xpath('(//div[contains(@class, " bookmap/bookmeta ")]//div[contains(@class, " bookmap/completed ")]/div[contains(@class, " bookmap/year ")]/text())[1]');
}
- or use a more specific path. For example, you should try collecting all "div" elements only from inside the div in the frontpage.
You could do that by adding somthing like:

Code: Select all

div[contains(@class, " front-page/front-page")]
at the very beginning of your path expression.

I hope this helps.

Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support

chrispitude
Posts: 66
Joined: Thu May 02, 2019 2:32 pm

Re: Ways to store CSS-accessible book metadata besides <bookmeta>?

Post by chrispitude » Fri Jun 07, 2019 5:29 pm

Thanks Costin! Yes, I've used a similar solution in my own CSS.

I would really like to eliminate the duplicated metadata itself. Is there a way to (1) prevent the DITA-OT from such excessive duplication, or (2) is there another way besides the <bookmeta> construct to communicate data from DITA source files to the CSS files?

Maybe I could put the book information into a nonprinting DITA topic and access that...

Dan
Posts: 428
Joined: Mon Feb 03, 2003 10:56 am

Re: Ways to store CSS-accessible book metadata besides <bookmeta>?

Post by Dan » Fri Oct 04, 2019 10:13 am

Please read here:
post55679.html#p55679

The idea is to add to the metadata section of the bookmap data elements that expand the needed keys. We are not pushing all the defined keys in the merged map because there are cases of large key pools (thousands).

Post Reply