Specialization: elements added in XSLT stylesheet are missing from PDF output

67 views
Skip to first unread message

Vlad Ivanov

unread,
May 24, 2017, 4:02:44 AM5/24/17
to DITA-OT Users

I'm using dita-ot 2.4. I need to add a new element into my document. It's supposed to be transformed into a set of different elements through XSL transformations. I have created a plugin which defines a new element and its attributes, and adds it into existing topic template. I have also added some basic XSL processing into an output processing plugin:


<xsl:attribute-set
name="rootelement"> <xsl:attribute name="font-weight">bold</xsl:attribute> </xsl:attribute-set> <xsl:template match="rootelement"> <fo:inline xsl:use-attribute-sets="rootelement"> <xsl:call-template name="commonattributes"/> <xsl:apply-templates/> </fo:inline> </xsl:template>


So, now I can write the following in my document and it will appear in bold (in PDF):


<rootelement>
test </rootelement>


However, what I was initially aiming for is to create a transformation for <rootelement> which would emit other elements, for example, like this:


<xsl:template
match="rootelement"> <b>Some text:</b> <xsl:value-of select="current()" /> <i>Some other text</i> </xsl:template>


The actual transformation is a bit more complex and involves tables, so I can't just apply display attributes to this element.


Here is a piece of stylesheet that seems to work:


<xsl:template
match="rootelement"> <xsl:text> Text: </xsl:text> <fo:inline xsl:use-attribute-sets="rootelement"> <xsl:call-template name="commonattributes"/> <xsl:apply-templates/> </fo:inline> </xsl:template>


Every instance of rootelement is prepended with "Text: ".

This stylesheet, on the other hand, does not produce expected results:


<xsl:template
match="rootelement"> <i> <xsl:text> Text: </xsl:text>

<xsl:apply-templates/>
  </i> <fo:inline xsl:use-attribute-sets="rootelement"> <xsl:call-template name="commonattributes"/> <xsl:apply-templates/> </fo:inline> </xsl:template>

The "Text: " part instead of being printed in italics just disappears. Moreover, just putting <rootelement><i>Text: </i> some text</rootelement> in the source XML works as expected (rootelement content includes %basic.ph).


What am I missing? I have read this tutotial and couldn't notice any key differences. I have also checked the _MERGED.xml file, and any elements I add in my XSLT transformation just disappear.

Radu Coravu

unread,
May 24, 2017, 4:52:16 AM5/24/17
to Vlad Ivanov, DITA-OT Users
Your XSLT template seems to match DITA elements and produce XSL:FO elements. There are no xsl:fo elements named "b" or "i", you need to produce from your XSLT template the equivalent XSL:FO fo:inline elements like: <fo:inline font-style="italic">text</fo:inline> <fo:inline font-weight="bold">text</fo:inline>

--
You received this message because you are subscribed to the Google Groups "DITA-OT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vlad Ivanov

unread,
May 24, 2017, 5:03:59 AM5/24/17
to DITA-OT Users, vlad.x.do....@gmail.com
Thank you, I got the idea wrong here. It works with fo elements. I don't think I need to produce DITA elements in stylesheets now, but if I did, what would be the approach? I've tried binding my plugin to a preprocess extension point and running the transformation from there on DITA elements, but I wasn't able to make all the next preprocessing steps to use the transformed version of documents.

среда, 24 мая 2017 г., 11:52:16 UTC+3 пользователь Radu Coravu написал:
To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.

Stefan Eike

unread,
May 24, 2017, 5:26:57 AM5/24/17
to DITA-OT Users, vlad.x.do....@gmail.com
Hi Vlad,

it depends what you want to do. Injecting new elements on the fly may lead to unwanted results. So if you really don't need it, don't do it. If you need to do it, you have to decide, whether you'd like to pipe your elements through preprocessing. In this case, use the preprocess.pre extension point. If not, use preprocess.post. You than can call any XSLT tasks from an Ant script. Does this help you?

Greetings,
Stefan

Vlad Ivanov

unread,
May 24, 2017, 5:56:53 AM5/24/17
to DITA-OT Users, vlad.x.do....@gmail.com
Hi Stefan,

thank you for answering. Yes, I did try to extend depend.preprocess.pre. I just didn't figure out how to tell DITA to use preprocessed output for next preprocessing steps. Here is a piece of log file produced:

preprocess.init:
     [echo] *****************************************************************
     [echo] * input = file.ditamap
     [echo] *****************************************************************

debug-filter:
   [filter] Using Xerces grammar pool for DTD and schema caching.
   [filter] Processing file.ditamap to (TEMP)/temp20170523132040105/file.ditamap
   [filter] Processing sections/section1.xml to (TEMP)/temp20170523132040105/sections/section1.xml


My target is called before preprocess.init, so even if I target the temporary directory in my preprocessing, files there will be overwritten.

Regards,

Vlad

Stefan Eike

unread,
May 24, 2017, 7:24:53 AM5/24/17
to DITA-OT Users, vlad.x.do....@gmail.com
You have to manipulate and overwrite the DITA files in the temp dir with your XSLT scripts.
Reply all
Reply to author
Forward
0 new messages