Reputation: 13
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!
Upvotes: 0
Views: 1022
Reputation: 52878
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
.
Upvotes: 2
Reputation: 8227
XSLT allows you to collect an XML document as a tree and then use that tree as your current context. In other words, you can do your own pre-processing of the "macros" you are using.
I suggest you create a namespace for your macros, making the debugging process easier.
Upvotes: 0
Reputation: 2125
Edit: removed my initial incorrect assumption
You can include one XSLT into another. So if you have many templates that share some definitions, put all of the shared definitions into one shared template and use <xsl:include>
to refer to the shared template.
Information on include
Upvotes: 0