pdf5-ml icon indicating copy to clipboard operation
pdf5-ml copied to clipboard

Trying to add a use-when attribute to an <xsl:import> tag

Open mmg-hinchey opened this issue 2 years ago • 4 comments

Hi, I wanted to create a new dita2fo.xml file that would coorilate to a doc.type value. The goal is that when I set the doc.type publishing paramater to 'profile' my new file is included in the build. If doc.type is empty, or filled with another value, my new file is not included.

I've added a link to my new file in a xml:import tag in the dita2fo_import.xml file. That works well. However, when I added a @use-when attribute, one of the following things happen:

  • My expression is not static, so I recieve the following error message: "Error in variable expression. Variables (other than XSLT 3.0 static variables) cannot be used in a static expression"
  • My express is static, but it doesn't apply the filter. I assume that meens it couldn't find the doc type.

Is it possible to reference the publishing paramaters as a stactic expression in the @use-when attribute?

Thank you.

mmg-hinchey avatar Aug 10 '22 17:08 mmg-hinchey

Could you show me your code?

ToshihikoMakita avatar Aug 11 '22 00:08 ToshihikoMakita

These are in the C:\DITA-OT-3x-WHR-PDF5-Beta\plugins\com.custom.pdf5.ml\xsl\dita2fo_import.xsl file:

    <xsl:variable name="DocTypeVer" static="yes" select="('doc.type')" ></xsl:variable>
<xsl:import href="dita2fo_markup.xsl" use-when="$DocTypeVer = 'profiling'"/>

Again, I'm trying to test against the doc.type publishing paramater. I've also added the value "profiling" to the doc.type in C:\DITA-OT-3x-WHR-PDF5-Beta\plugins\com.custom.pdf5.ml\plugin.xml.

      <param name="doc.type" desc="Specifies document type such as 'UM' (User's manual), 'IM' (Installation manual)" type="enum">
		<val default="true"></val>
		<val>IFU</val>
		<val>IFU10</val>
		<val>addendum</val>
		<val>CableMap</val>
		<val>profiling</val>
        </param>	

This configuration creates valid output, but the dita2fo_markup.xsl is not being used. If I remove the @use-when attribute, the dita2fo_markup.xsl is used (but, of course, I need it to be conditional).

Thank you!

mmg-hinchey avatar Aug 11 '22 12:08 mmg-hinchey

You are trying to reference ant property from xsl:variable/@select attribute. Usually, Saxon XSLT processor needs system-property() described in @select attribute.

Try following steps.

1. Add following line in your com.custom.pdf5.ml\plugin.xml.

<feature extension="com.antennahouse.pdf5.ml.param" value="params.xml" type="file"/>

2. Implement param.xml in your plug-in folder.

<?xml version="1.0" encoding="UTF-8"?>
<extension>
    <sysproperty key="doc.type" value="${doc.type}"/>
</extension>

3. Change your dita2fo_import.xsl as follows.

 <xsl:import href="dita2fo_markup.xsl" use-when="system-property('doc.type') eq 'profiling'"/>

I have not tried but I used this method in the following example.

com.antennahouse.pdf5.ml/build_transform_template.xml line 178.

<sysproperty key="use.i18n.index.lib" value="${use.i18n.index.lib}"/>

com.antennahouse.pdf5.ml\xsl\dita2fo_indexshell.xsl line 24.

<xsl:include href="dita2fo_indexi18n.xsl" use-when="system-property('use.i18n.index.lib') eq 'yes'"/>

Hope this helps your solution.

ToshihikoMakita avatar Aug 11 '22 13:08 ToshihikoMakita

https://github.com/AntennaHouse/pdf5-ml/issues/231#issue-1334922385

kayal28 avatar Sep 01 '22 02:09 kayal28