Insert/Preserve XSL Attribute Values in PDF Output

Here should go questions about transforming XML with XSLT and FOP.
dreifsnider
Posts: 9
Joined: Thu Aug 30, 2018 10:06 pm

Insert/Preserve XSL Attribute Values in PDF Output

Post by dreifsnider » Fri Aug 31, 2018 12:37 am

Hello!

I'm trying to find some way to insert/preserve the xsl attribute names and their values that are applied to fo objects in the final PDF deliverable. I'm looking to create a stylesheet of all the attribute sets that are used and applied to all nodes for my custom PDF plugin.

Ideally, I would like something along the lines of:

Code: Select all

<fo:block attribute1="value" attribute2="value">Some text attribute 1:value attribute2:value</fo:block>
for all fo objects (fo:inline, fo:block, fo:table, etc.)

I've tried creating a template that matches every node and inserts the local-name of the node:

Code: Select all


  <xsl:template match="*">
<xsl:for-each select=".">
<xsl:value-of select="local-name()"/>
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
but this isn't giving me the desired result, because this just returns the node name and not the attributes that are applied. I'm wondering if I need to add a post-processing step that would comb through the topic.fo?

Any help on this would be greatly appreciated.

Thanks!

-Daniel

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

Re: Insert/Preserve XSL Attribute Values in PDF Output

Post by Radu » Mon Sep 03, 2018 5:45 pm

Hi Daniel,

I'm not sure how you could do this, indeed probably as another post processing step on the XSL-FO output (setting the "clean.temp" parameter to "no" so that the XSL-FO file remains in the transformation temporary folder).
And in order to iterate an element's attributes you need to probably do it like this:

Code: Select all

 <xsl:template match="*">
<xsl:for-each select="@*">
<xsl:value-of select="local-name()"/>
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

dreifsnider
Posts: 9
Joined: Thu Aug 30, 2018 10:06 pm

Re: Insert/Preserve XSL Attribute Values in PDF Output

Post by dreifsnider » Wed Sep 05, 2018 8:20 pm

Hi Radu,

Thanks for your reply and code example! I'll try working on something and see what I come up with.

In the interim, do you know of any other way that I could obtain all the styling used for a PDF plugin other than manually combing through all the templates and the attribute sets they call?

Cheers,

-Daniel

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

Re: Insert/Preserve XSL Attribute Values in PDF Output

Post by Radu » Thu Sep 06, 2018 8:16 am

Hi Daniel,

Other than looking at the final XSL-FO file to see how certain XML elements have been mapped to XSL-FO elements I'm not sure how this could be handled. Maybe you can try to register and ask around on the DITA Users List.
Honestly our main improvement direction when it comes to creating PDF from DITA is focus towards using CSS to style the DITA content and obtain the PDF. CSS-based styling is way easier to debug, you can even do that with a web browser or with Oxygen's own CSS Inspector view. And it's also way easier to write and maintain.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

dreifsnider
Posts: 9
Joined: Thu Aug 30, 2018 10:06 pm

Re: Insert/Preserve XSL Attribute Values in PDF Output

Post by dreifsnider » Thu Sep 06, 2018 8:30 pm

Thanks for the reply Radu.

I'm actually starting to look into using the CSS Paged Media and PDF Chemistry, because I'm getting a little tired of XSL-FO. :)

Thanks again for your help with this.

Cheers!

Daniel

Post Reply