How can I combine xsl:attribute and xsl:use-attribute-sets to conditionally use an attribute set?
- by Peter
We have an xml node "item" with an attribute "style", which is "Header1". This style can change however. We have an attribute set named Header1 which defines how this should look in a PDF, generated through xsl:fo.
This works (the use-attribute-sets is mentioned inline, in the fo:table-cell node):
<xsl:template match="item[@type='label']">
<fo:table-row>
<fo:table-cell xsl:use-attribute-sets="Header1">
<fo:block>
<fo:inline font-size="8pt" >
<xsl:value-of select="." />
</fo:inline>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
But this doesn't (using xsl:attribute, because the attribute @style can also be Header2 for example). It doesn't generate an error, the PDF is created, but the attributes aren't applied.
<xsl:template match="item[@type='label']">
<fo:table-row>
<fo:table-cell>
<xsl:attribute name="xsl:use-attribute-sets">
<xsl:value-of select="@style" />
</xsl:attribute>
<fo:block>
<fo:inline font-size="8pt" >
<xsl:value-of select="." />
</fo:inline>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
Does anyone know why? And how we could achieve this, preferably without long xsl:if or xsl:when stuff?