Tracing templates in front-matter.xsl for PDF2

Here should go questions about transforming XML with XSLT and FOP.
jnielsen
Posts: 58
Joined: Fri Sep 12, 2008 12:12 am

Tracing templates in front-matter.xsl for PDF2

Post by jnielsen »

This is just a curiosity for me, but I wanted to know where the templates are that finally pull the values for what is in author tags, and copyright tags, etc for ditamap metadata in the <DITA-OT>\demo\fo\xsl\fo\front-matter.xsl file? Under the code to generate the title and subtitle there is a match for topicmeta tags which I traced to another template below that that says <xsl:template match="*[contains(@class, ' map/topicmeta ')]"> but then inside just says "<xsl:apply-templates/>" instead of an <xsl:value-of> assignment like I would expect. All the other similar templates do the same. Where are the final templates that extract the values from the tags?

In the "createFrontMatter" template there, for example, is an explicit call to a template (<xsl:call-template name="insertFrontMatterStaticContents"/>)that I traced to commons.xsl but after looking in commons and other .xsl files in the directory I cannot similarly figure out which templates the author, copyright, etc. tags are gotten from.

Any ideas about how to trace this?
Radu
Posts: 9439
Joined: Fri Jul 09, 2004 5:18 pm

Re: Tracing templates in front-matter.xsl for PDF2

Post by Radu »

Hello Josh,

I searched for topic/author which is the class value for the <author> tag in all the stylesheets from the OXYGEN_INSTALL_DIR\dita\DITA-OT\demo\fo\xsl\fo directory using the Oxygen Find/Replace in Files.
In the OXYGEN_INSTALL_DIR\dita\DITA-OT\demo\fo\xsl\fo\front-matter.xsl at line 104 you have the template which mathes the author tag:

Code: Select all


 <xsl:template match="*[contains(@class, ' topic/author ')]">
<fo:block xsl:use-attribute-sets="author" >
<xsl:apply-templates/>
</fo:block>
</xsl:template>
The <xsl:apply-templates/> means that all other templates which can match the contents of the <author> tag will be applied.
This usually means that the text of the author will be output there.

The attribute-set used by the author xsl:use-attribute-sets="author" can be found defined in OXYGEN_INSTALL_DIRdita\DITA-OT\demo\fo\cfg\fo\attrs\commons-attr.xsl

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jnielsen
Posts: 58
Joined: Fri Sep 12, 2008 12:12 am

Re: Tracing templates in front-matter.xsl for PDF2

Post by jnielsen »

Hello Radu,
Radu wrote:I searched for topic/author which is the class value for the <author> tag in all the stylesheets from the OXYGEN_INSTALL_DIR\dita\DITA-OT\demo\fo\xsl\fo directory using the Oxygen Find/Replace in Files.
In the OXYGEN_INSTALL_DIR\dita\DITA-OT\demo\fo\xsl\fo\front-matter.xsl at line 104 you have the template which mathes the author tag:
Yes that was the template I was referring to. Thank you for making that more specific.
The <xsl:apply-templates/> means that all other templates which can match the contents of the <author> tag will be applied.
This usually means that the text of the author will be output there.
Well I understand it is calling any other templates that will match for that context node (the <author> tag in this case), however I have not been able to find any other templates that match it in the xsl files, and other related templates just have more <xsl:apply-templates/> statements, it seems, recursively - like the map/topicmeta template applying templates which will eventually call the topic/author template if there are any <author> tags, which in turn applies more templates which I have not been able to further trace. But I still do not see which template applies/extracts the text inside the author tag.

In <DITA-OT>\demo\fo\cfg\fo\commons.xsl on lines 712-718 it has a stub template, which does nothing at the moment because its contents are commented out, but which matches the author tag:

Code: Select all

<xsl:template match="*[contains(@class, ' topic/author ')]">
<!--
<fo:block xsl:use-attribute-sets="author">
<xsl:apply-templates/>
</fo:block>
-->
</xsl:template>
However I have seen no other templates to match topic/author that actually do something with the tag. Establishing a block with attribute sets is not enough to pull the value from the author context nodes is it? For that I should expect an <xsl:value-of> or some equivalent statement to extract the value, right? Do you see what I am asking?

That's alright if you don't know, but I just wanted to see if anyone had an explanation.
The attribute-set used by the author xsl:use-attribute-sets="author" can be found defined in OXYGEN_INSTALL_DIRdita\DITA-OT\demo\fo\cfg\fo\attrs\commons-attr.xsl
Right, I have looked at the attribute xsl files associated with various templates used in front-matter.xsl


Regards,

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

Re: Tracing templates in front-matter.xsl for PDF2

Post by Radu »

Hi Josh,

If a stylesheet does not match text() nodes explicitly in a template there are default rules which apply and make the entire text be output by default.
See this link for more details:
http://www.w3.org/TR/xslt#built-in-rule

For example this stylesheet:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
will output all text nodes even if there is no specific template matching text().

You can overwrite the default template which matches text nodes like:

Code: Select all


<xsl:template match="text()|@*">
<xsl:value-of select="."/>
</xsl:template>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jnielsen
Posts: 58
Joined: Fri Sep 12, 2008 12:12 am

Re: Tracing templates in front-matter.xsl for PDF2

Post by jnielsen »

Thank you Radu! I did not know about that built-in rule. That helps me understand what is going on in the template a whole lot better now.

Thanks!

Josh
Post Reply