DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post here questions and problems related to editing and publishing DITA content.
Benny
Posts: 11
Joined: Wed Mar 01, 2017 12:33 pm

DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Benny »

Dear all,

I am building templates for a datasheet written in DITA. I am using the Oxygen DITA map PDF – based on HTML5 &CSS transformation. This really works great I have to say, it is the first time I can almost get everything I want to get working in the layout work for DITA!

However now I encounter a problem for which I need an xslt extension point. And then my knowledge get limited.

What I want is the following. Now my datasheet.merged.html contains the following code:

Code: Select all


<div class=" front-page/front-page-title front-page-title">
<div class="- topic/title title">product name</div>
</div>
And I want:

Code: Select all


<div class=" front-page/front-page-title front-page-title">
<div class="doctype">datasheet</div>
<div class="- topic/title title">product name</div>
</div>
Looking at examples I made the following extension xslt:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:oxyf="http://www.oxygenxml.com/functions"
exclude-result-prefixes="xs"
version="2.0">

<xsl:template match="*[contains(@class, ' topic/title ')]">
<div class="doctype">Datasheet</div>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
In the opt file I have the following:

Code: Select all


<xslt>
<extension id="com.oxygenxml.pdf.css.xsl.merged2merged" file="xslt/document-type.xsl"/>
</xslt>
This partially does the Job, with the following problems:

1. match="*[contains(@class, ' topic/title ')]" makes that this change is applied to all topic titles. I only want it to be applied to the topic/title in the “front-page/front-page-title front-page-title” div. I tried using the front-page/front-page-title front-page-title in the match, but that did not change the output in any way. How can I get this working?

2. I don’t understand why this change does not work if in the opt file I use the id “com.oxygenxml.pdf.css.xsl.merged2html5”. Could somebody explain that? I read the user manual and I know there are two phases to apply changes but I thought this change had to be applied after the conversion to HTML while now it only seems to work before that conversion.

3. In my pdf I get the following text: [/map/concept/div {"doctype"}) datasheet (div], marked yellow, where does that come from?

Maybe anybody of you can give me new ideas where to search and what to try next.

Thanks,

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

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Dan »

The extension should be bound to the last transformation, the merge2html5. it is currenlty bound to merged2merged in your publishing template, so please correct to:

Code: Select all


<xslt>
<extension id="com.oxygenxml.pdf.css.xsl.merged2html5" file="xslt/document-type.xsl"/>
</xslt>
In this way the XSLT template will apply on the HTML merged map, and you should be able to match and generate HTML elements.

You can use:

Code: Select all


 <xsl:template match="*[contains(@class, ' front-page/front-page-title ')]">
<div class="doctype">Datasheet</div>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Many regards,
Dan
Benny
Posts: 11
Joined: Wed Mar 01, 2017 12:33 pm

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Benny »

Dear Dan,

Thanks for your reply.

However I tried this before and now double checked, but when I do what you say nothing is changed in the document.

I get the same output as if the xslt extension was not there.

That's also the reason why I asked question 2 because also for me it would have been more logical that the merged2html5 id should be used.
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Dan »

Let the XSL extend the merged2html5 extesion point.

Try adding a mode="#all" on the template.

Code: Select all

 
<xsl:template match="*[contains(@class, ' front-page/front-page-title ')]" mode="#all">
<div class="doctype">Datasheet</div>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Please let us know if it worked for you.

Many regards,
Dan
Benny
Posts: 11
Joined: Wed Mar 01, 2017 12:33 pm

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Benny »

Dear Dan,

Thanks, adding the mode="all" seems to at least do something. However it also seems to do some other unwanted stuff. The result in the merged.html looks like below. i.e. the original div element seems to be replaced by the oxy:front-page-title element.

Maybe something in the <xsl:copy> part should be changed? Probably writing out the original code would also do the Job. Any clue what could go wrong here? else I will try the writing out the original part.

Code: Select all


<div xmlns:oxyf="http://www.oxygenxml.com/functions" class="doctype">Datasheet</div>
<oxy:front-page-title xmlns:oxy="http://www.oxygenxml.com/extensions/author"
xmlns:opentopic-index="http://www.idiominc.com/opentopic/index"
class=" front-page/front-page-title ">
<span style="background-color: yellow;">
<span style="font-weight: bold"> [/map/oxy:front-page/oxy:front-page-title/title {"- topic/title "}) </span>
TMX50-40x/CXP
<span style="font-weight: bold"> (title]</span>
</span>
</oxy:front-page-title>
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Dan »

Yes, the "copy" element will simply copy the oxy: element from the merged map to the HTML output.

You should replace it by a div or other element:

Code: Select all


<xsl:template match="*[contains(@class, ' front-page/front-page-title ')]" mode="#all">
<div class="doctype">Datasheet</div>
<div>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</div>
</xsl:template>
Benny
Posts: 11
Joined: Wed Mar 01, 2017 12:33 pm

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Benny »

Dear Dan,

The above code provides below result, still not what I am looking for unfortunately.

Code: Select all


<div class=" front-page/front-page front-page">
<div xmlns:oxyf="http://www.oxygenxml.com/functions" class="doctype">Datasheet</div>
<div xmlns:oxyf="http://www.oxygenxml.com/functions" class=" front-page/front-page-title ">
<span style="background-color: yellow;">
<span style="font-weight: bold">
[/map/oxy:front-page/oxy:front-page-title/title {"- topic/title "})
</span>
Product name
<span style="font-weight: bold"> (title]</span>
</span>
</div>
</div>
I did some more testing and up to now only this works, but I think it should be possible to make it more general without copying the code from the original output.

Code: Select all


<xsl:template match="*[contains(@class, ' front-page/front-page-title ')]" mode="#all">
<div class=" front-page/front-page front-page">
<div class=" front-page/front-page-title front-page-title">
<div class="doctype">Datasheet</div>
<div class="- topic/title title">
<xsl:value-of select="."/>
</div>
</div>
</div>
</xsl:template>
Something that came close in how it looked in the pdf was:

Code: Select all


<xsl:template match="*[contains(@class, ' front-page/front-page-title ')]"  mode="#all">
<div class="doctype">Datasheet</div>
<xsl:copy-of select="."/>
</xsl:template>
But the resulting code in the merged file looks ugly:

Code: Select all


<div class=" front-page/front-page front-page">
<div xmlns:oxyf="http://www.oxygenxml.com/functions" class="doctype">Datasheet</div>
<oxy:front-page-title xmlns:oxy="http://www.oxygenxml.com/extensions/author"
xmlns:opentopic-index="http://www.idiominc.com/opentopic/index" class=" front-page/front-page-title ">
<title xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
xmlns:opentopic="http://www.idiominc.com/opentopic"
xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder" class="- topic/title ">
Product name
</title>
</oxy:front-page-title>
</div>
What are all the xmlns? Is there actually something like a "identity transformation"? Like described here: https://stackoverflow.com/questions/568 ... -with-xslt
If I try the code suggested here the code in the merged file is still looking different.
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Dan »

My mistake, please add a mode="#current" on the apply-templates:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">

<xsl:template match="*[contains(@class, ' front-page/front-page-title ')]" mode="#all">
<div class="doctype">Datasheet </div>
<div>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="#current"/>
</div>

</xsl:template>

</xsl:stylesheet>
You should obtain in the merged HTML file:

Code: Select all


	<div class=" front-page/front-page front-page">
<div class="doctype">Datasheet</div>
<div class=" front-page/front-page-title ">
<div class="- topic/title bookmap/booktitle title booktitle">
<div class="- topic/ph bookmap/mainbooktitle ph mainbooktitle">Test
map</div>
</div>
</div>
</div>
If you still have problems, please write on our support email address, so I can send you a zip with a complete example.
Many regards,
Dan
Benny
Posts: 11
Joined: Wed Mar 01, 2017 12:33 pm

Re: DITA map PDF – based on HTML5 &CSS transformation with xslt extension points

Post by Benny »

Thanks Dan,

This solution works!

Best regards,

Benny
Post Reply