Arbitrary elements in Prolog

Post here questions and problems related to editing and publishing DITA content.
sweetsweetstefan
Posts: 6
Joined: Mon Jan 03, 2022 5:54 pm

Arbitrary elements in Prolog

Post by sweetsweetstefan »

Hi there! I am using Oxygen XML Author v24 to output articles in Markdown (GitHub flavoured). So far everything is great, except for one requirement: I need a YAML header at the top of my articles with some metadata. Here is what I need:

Code: Select all

---
title:  "Human-readable title"
slug: title-for-location-bar
---
I've experimented with the Prolog element, and the Author element renders in the same general way that I need, but my publishing software needs the two keys I mention above, title and slug. I tried adding Othermeta and Data elements, but unlike the Author element, the transformation does not render Othermeta and Data elements to Markdown. I also tried adding a new DITA element to my metaDecl.mod file, but I wasn't able to get it to work.

Before trying with the Prolog element, I tried modifying the dita2markdownImpl.xsl file and adding a new template that generates what I need, but it started to get too complicated.

Does anyone have any ideas on how I might be able to get this to work? Thanks for any help!
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Arbitrary elements in Prolog

Post by Radu »

Hi,

You probably need to make indeed changes in the XSLTs used to generate the Markdown content, for example in OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT3.x/plugins/org.lwdita/xsl/dita2markdown.xsl make these changes to the template which generates the entire file:

Code: Select all

<xsl:template match="/">
    <xsl:variable name="ast" as="node()">
      <xsl:apply-templates/>
    </xsl:variable>
    <xsl:variable name="ast-flat" as="node()">
      <xsl:apply-templates select="$ast" mode="flatten"/>
    </xsl:variable>
    <xsl:variable name="ast-clean" as="node()">
      <xsl:apply-templates select="$ast-flat" mode="ast-clean"/>
    </xsl:variable>
---
title:  "<xsl:value-of select="($ast-clean/header)[1]"/>"
slug: title-for-location-bar
---
<xsl:apply-templates select="$ast-clean" mode="ast"/>
  </xsl:template>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sweetsweetstefan
Posts: 6
Joined: Mon Jan 03, 2022 5:54 pm

Re: Arbitrary elements in Prolog

Post by sweetsweetstefan »

Hi Radu,
Thank you for the suggestion! I agree, I think that's where it has to be inserted. I'll experiment and we'll see what happens!

Regards,
Stefan
im_rem
Posts: 20
Joined: Tue Jun 14, 2022 1:08 pm

Re: Arbitrary elements in Prolog

Post by im_rem »

Hello *,
we also try to do a markdown output with metadata in a YAML section at the top of each file.
Using <xsl:value-of select="($ast-clean/header)[1]"/> or similar paths like ($ast-clean/prolog/metadata/othermeta)[1] does not fill in any YAML values in my outputs. Is there maybe a description of this AST so that we know what path to use?
Kind regards
Nicole
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Arbitrary elements in Prolog

Post by Radu »

Hi Nicole,

In the XSLT stylesheet you can output an xsl:message, something like this:

Code: Select all

<xsl:message><xsl:copy-of select="$ast-clean/"/></xsl:message>
and the message should be visible after publishing in the DITA OT console tab view. In the Oxygen Preferences->"DITA / Logging" page you can set "Show console output->Always" to always show the DITA OT console view while publishing.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
im_rem
Posts: 20
Joined: Tue Jun 14, 2022 1:08 pm

Re: Arbitrary elements in Prolog

Post by im_rem »

Good morning,
that helped. With the log I found out that, at the point where the dita2markdown.xsl is being evalueted, DITA-OT already stripped <othermeta> contents from the topics. There is no DITA-OT paramater to preserve all <metadata> or <data> either. Does someone know if there are plans on adding this in the future?
A workaround would be that I create HTML output in parallel and write a batch program to merge the metadata into the MD-files. But that seems a bit overkill to me.
If someone knows a different approach, please let us know here.
Kind regards
Nicole
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Arbitrary elements in Prolog

Post by Radu »

Hi Nicole,

Let's try to take a small example, for example this topic:

Code: Select all

<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="introduction">
    <title>Introduction</title>
  <prolog>
    <metadata>
      <othermeta name="some" content="value"/>
    </metadata>
  </prolog>
    <body>
    </body> 
</topic>
referenced in a small DITA Map and then the DITA Map published to Markdown.
In the "DITA-OT3.x/plugins/org.lwdita/xsl/dita2markdown.xsl" stylesheet I added an xsl:message:

Code: Select all

  <xsl:template match="/">
    <xsl:message>I AM <xsl:copy-of select="."/></xsl:message>
I run the publishing and in the DITA OT console view I see at some point:

Code: Select all

     [xslt]          <othermeta class="- topic/othermeta "
     [xslt]                     content="value"
     [xslt]                     name="some"
     [xslt]                     xtrc="othermeta:1;7:47"
So the metatadata content inside the topic seems to be preserved and is present when the stylesheet is applied.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
im_rem
Posts: 20
Joined: Tue Jun 14, 2022 1:08 pm

Re: Arbitrary elements in Prolog

Post by im_rem »

Ok, so it must be xsl:copy-of select="." instead of xsl:copy-of select="$ast-clean". This worked and returned the original DITA markup including all prolog contents.
Thank you for the hint! :)
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Arbitrary elements in Prolog

Post by Radu »

Hi,

Indeed it seems in the XSLT stylesheet "plugins/org.lwdita/xsl/ast2markdown.xsl" there is this template:

Code: Select all

  <xsl:template match="@* | node()"
                mode="ast-clean" priority="-10">
in the mode "ast-clean", used when the $ast-clean variable is being computed which ignores most of the DITA elements from the original document.

Regards,
Radup
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply