I know that XSLT itself has attribute-sets, but that forces me to use
<xsl:element name="fo:something">
every time I want to output an
<fo:something>
tag. Is there anything in the XSL-FO spec that would allow me to specify (let's say) a default set of attributes (margin, padding, etc.) for all Tables in the FO output?
Essentially I'm looking for the functionality of CSS, but for FO output instead of HTML.
No, you are not required to use xsl:element, the use-attribute-sets attribute can appear on literal result elements if you place it in the XSLT namespace, so you can use something like:
<fo:something xsl:use-attribute-sets="myAttributeSet">
If you want to have something close to the CSS functionality then you can add another XSLT transformation at the end of your processing that adds the attributes that you want. You can start with a recursive identity transformation and then add templates matching on the elements you want to change, see a small example below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:attribute-set name="commonAttributes">
<xsl:attribute name="common">value</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="someElement">
<xsl:copy use-attribute-sets="commonAttributes">
<xsl:attribute name="someAttribute">someValue</xsl:attribute>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With