passing param to xslt in dita ot

Oxygen general issues.
dledle
Posts: 3
Joined: Thu Apr 04, 2024 4:34 pm

passing param to xslt in dita ot

Post by dledle »

Hi all,

Im trying to use a custom plugin for pdf. I've been following Dita for Print book. But nothing I found is helping with this issue.
I want to have a footer that displays security clearance level. I would like this specified as a parameter in the command line.
So adding -Dseclevel=internal will give me "this document is for internal use". This text is in a localization file en.xml.
-Dseclevel=restricted will give me "this document is restricted" etc etc.

As of right now, the only way it seems to work is if I edit the base build.xml file directly, which is what I do not want.
I would need to add this parameter

Code: Select all

<param name="seclevel" expression="${seclevel}" if="seclevel"/>


into
File:
\dita-ot-4.2.4\plugins\org.dita.pdf2\build.xml
under

Code: Select all

<target name="transform.topic2fo.main">
<pipeline>
<xslt>
[b]<custom parameter here>[/b]
I want to avoid this. I thought by having an insertParameters file with the feature extension in the plugin would work but no.

Here is my setup in the custom plugin folder
command line:

Code: Select all

dita -imap.ditamap -f print-pdf -Dseclevel=restricted -d -l log.xml -v
plugin:

Code: Select all

<plugin id="auto_pdf" >
	<require plugin="org.dita.pdf2"/>
	<transtype name="print-pdf" extends="pdf" desc="PDF on A4 paper"/>
	<feature extension="dita.transtype.print" value="print-pdf"/>
	<feature extension="ant.import" file="integrator.xml"/>
	
	<feature extension="dita.conductor.pdf2.param" file="insertParameters.xml"/>
</plugin>
integrator:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <target name="dita2print-pdf"
       depends="dita2print-pdf.init,
                dita2pdf2">
                </target>
  <target name="dita2print-pdf.init">
    <property name="customization.dir"
          location="${dita.plugin.auto_pdf.dir}/cfg"/>
       
  </target>
</project>
insertParameters.xml

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<dummy>
	<param name="seclevel" expression="${seclevel}" if="seclevel"/>
</dummy>

I add more details below (which I will append to my parent post)
In my plugin folder, I have my attr and my xsl.
cfg > common
> fo > attrs
> xsl

Looking at my fo > xsl folder:
I have a custom.xsl

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:fo="http://www.w3.org/1999/XSL/Format"
                version="2.0">
                
  <xsl:import href="../layout-masters.xsl"/>
  
  <xsl:import href="commons.xsl"/>
  <xsl:import href="root-processing.xsl"/>
  <xsl:import href="static-content.xsl"/>
  <xsl:import href="front-matter.xsl"/>
  <xsl:import href="topic.xsl"/>
  <xsl:import href="tables.xsl"/>

</xsl:stylesheet>
static-content.xsl is where I have my footer.
within it:

Code: Select all

<fo:table-cell text-align="center">
                            <fo:block font-size="8pt" font-weight="bold" color="black">
                                <xsl:choose>
                                    <xsl:when test="$seclevel">
                                        <xsl:call-template name="getVariable">
                                            <xsl:with-param name="id" select="concat('securitylevel ', $seclevel)"/>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:with-param name="id" select="'securitylevel default'"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </fo:block>
                        </fo:table-cell>
I use the getVariable to look up the value I have in an en.xml file.
Last edited by dledle on Fri Jan 10, 2025 3:13 pm, edited 1 time in total.
julien_lacour
Posts: 665
Joined: Wed Oct 16, 2019 3:47 pm

Re: passing param to xslt in dita ot

Post by julien_lacour »

Hello,

Starting from your plugin I modified it to use <feature extension="dita.xsl.xslfo" file="custom.xsl"/> instead of the additional Ant target,
org.dita.pdf2.custom.zip
I declared <xsl:param name="seclevel"/> in the XSL and log it using <xsl:message>, with this plugin you should obtain the following console log:

Code: Select all

dita -v -f print-pdf -i flowers.ditamap -o out/print-pdf -Dseclevel=restricted

==> Build FO
...
SECURITY=restricted
I also add all templates used by the pdf2 plugin to create footers, you can start from these templates to create your own.

Regards,
Julien
You do not have the required permissions to view the files attached to this post.
dledle
Posts: 3
Joined: Thu Apr 04, 2024 4:34 pm

Re: passing param to xslt in dita ot

Post by dledle »

Hi Julien, thanks for the suggestion. But after trying a few more things I still couldn't get it to work.
I tried creating another xsl file containing only the param. Then using <feature extension="dita.xsl.xslfo" file="pathto param2xlsfo.xsl"/>. No luck there.

I add more details below (which I will append to my parent post)
In my plugin folder, I have my attr and my xsl.
cfg > common
> fo > attrs
> xsl

Looking at my fo > xsl folder:
I have a custom.xsl

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:fo="http://www.w3.org/1999/XSL/Format"
                version="2.0">
                
  <xsl:import href="../layout-masters.xsl"/>
  
  <xsl:import href="commons.xsl"/>
  <xsl:import href="root-processing.xsl"/>
  <xsl:import href="static-content.xsl"/>
  <xsl:import href="front-matter.xsl"/>
  <xsl:import href="topic.xsl"/>
  <xsl:import href="tables.xsl"/>

</xsl:stylesheet>
static-content.xsl is where I have my footer.
within it:

Code: Select all

<fo:table-cell text-align="center">
                            <fo:block font-size="8pt" font-weight="bold" color="black">
                                <xsl:choose>
                                    <xsl:when test="$seclevel">
                                        <xsl:call-template name="getVariable">
                                            <xsl:with-param name="id" select="concat('securitylevel ', $seclevel)"/>
                                        </xsl:call-template>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:with-param name="id" select="'securitylevel default'"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </fo:block>
                        </fo:table-cell>
I use the getVariable to look up the value I have in an en.xml file.
julien_lacour
Posts: 665
Joined: Wed Oct 16, 2019 3:47 pm

Re: passing param to xslt in dita ot

Post by julien_lacour »

Hello,

I modified my plugin to use more XSL stylesheet:
org.dita.pdf2.custom.zip
If you test it you will see that the property is used and the footer did contain the text.

Inside the plugin I've set <feature extension="dita.xsl.xslfo" file="custom.xsl"/> with the content you gave me and in static-content.xsl I've declared the parameter at the beginning of the stylesheet, the seclevel value must appear in the console and in the output.

Regards,
Julien
You do not have the required permissions to view the files attached to this post.
Post Reply