Page 1 of 1

XSL: apply fontdef to <keyword> element except when <keyword> is nested in <title>

Posted: Tue May 28, 2019 11:47 pm
by pieterjan_vdw
Hi,

I would like to achieve the following:
have italics fontdef to all <keyword outputclass="column"> elements in my PDF file (Miramo),
except when <keyword outputclass="column"> is nested in the title

Example:

Code: Select all

<concept id="aa1258889" xml:lang="en-us">
   <title>This is my title (<keyword outputclass="column">No Italics keyword</keyword>) </title>
   <conbody>
<p><keyword outputclass="column">Italics keyword</keyword></p>
</conbody>
</concept>
this is my xslt

Code: Select all

<xsl:template match="*[contains(@class,' topic/keyword ')]">
<xsl:choose>
<xsl:when test="@outputclass='column'[not(self::title/keyword[@outputclass='column'])]">
	         <Font fontDef="italic">
               <xsl:apply-templates/>
            </Font>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-imports/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
Anyone who can help me with the

Code: Select all

<xsl:when test...>
part

Thank you

Re: XSL: apply fontdef to <keyword> element except when <keyword> is nested in <title>

Posted: Wed May 29, 2019 7:54 am
by Radu
Hi,

I think the template match should look something like:

Code: Select all

<xsl:template match="*[contains(@class,' topic/keyword ')][not(ancestor::*[contains(@outputclass, ' topic/title ')])]">
About a year or two ago we added a new way to obtain PDF from DITA using CSS to style the output:

https://www.oxygenxml.com/doc/versions/ ... 5-x-2.html

and of course with CSS doing something like this is a snap:

Code: Select all

keyword {
    font-family: "Arial";
}
title keyword {
    font-family: inherit;
}
Regards,
Radu

Re: XSL: apply fontdef to <keyword> element except when <keyword> is nested in <title>

Posted: Wed May 29, 2019 11:07 am
by pieterjan_vdw
Thanks Radu, also for the CSS suggestion. I'll give it a try.

I had to make a small change to the XSL suggestion. I add it for future reference.

Code: Select all

[not(ancestor::*[contains(@class, ' topic/title ')])]">
instead of

Code: Select all

[not(ancestor::*[contains(@outputclass, ' topic/title ')])]">

Code: Select all

<xsl:template match="*[contains(@class,' topic/keyword ')][not(ancestor::*[contains(@class, ' topic/title ')])]">