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

Here should go questions about transforming XML with XSLT and FOP.
pieterjan_vdw
Posts: 21
Joined: Wed Jun 20, 2018 11:30 am

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

Post by pieterjan_vdw » Tue May 28, 2019 11:47 pm

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

Radu
Posts: 6436
Joined: Fri Jul 09, 2004 5:18 pm

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

Post by Radu » Wed May 29, 2019 7:54 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

pieterjan_vdw
Posts: 21
Joined: Wed Jun 20, 2018 11:30 am

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

Post by pieterjan_vdw » Wed May 29, 2019 11:07 am

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 ')])]">

Post Reply