Search code examples
xmlxsltxsl-foapache-fop

XSLT - Own/Custom Tags (for Styling)


i want to specify own Tags like: for my XSL Files because i have many redundant Blocks for styling:

<fo:block font-weight="bold" margin-bottom="1cm" color="#424242"> ... </fo:block>

So what i want is to take this <fo:block> element and put it in an much shorter Tag, so that i dont need to write this again and again and have only one simple Tag for this.

I googled now for hours and can't find a solution or someone who say "Impossible".

I hope you can help me!


Solution

  • One option that is fairly close to what you want is to use an xsl:attribute-set

    Example:

    <xsl:attribute-set name="headline">
        <xsl:attribute name="font-weight" select="'bold'"/>
        <xsl:attribute name="margin-bottom" select="'1cm'"/>
        <xsl:attribute name="color" select="'#424242'"/>
    </xsl:attribute-set>
    
    <xsl:template match="foo">
        <fo:block xsl:use-attribute-sets="headline">...</fo:block>
    </xsl:template>
    

    Note: If you're using XSLT 1.0, you can't use select in xsl:attribute.