2

I'm working with some third-party XSLT that makes heavy use of attribute sets for transforming XML to various forms of XSL:FO. Example:

notes.xsl:

<xsl:template match="note">
    <fo:block xsl:use-attribute-sets="noteAttrs">
        <!-- This is a pretty big template with lots of xsl:choose/xsl:if/etc. -->
     </fo:block>
<xsl:template>

<xsl:attribute-set name="noteAttrs">
    <xsl:attribute name="margin-left">10px</xsl:attribute>
    <xsl:attribute name="margin-right">8px</xsl:attribute>
    <xsl:attribute name="margin-top">5px</xsl:attribute>
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <!-- several other attributes -->
</xsl:attribute>

The idea is that I import this XSLT, redefining the attribute sets as I see fit. If I just need a different font size for a given .fo document...

<xsl:import href="notes.xsl"/>
<xsl:attribute-set name="noteAttrs">
    <xsl:attribute name="font-size">12pt</xsl:attribute>
</xsl:attribute>

The problem is that sometimes I need to flat out remove attributes (i.e. so I inherit from the containing fo:block), or a given fo document is going to be so different that it would be easier to start fresh instead of merge my attribute set with the one from notes.xsl. Is there a way in XSLT 2.0 to do that without reproducing the entire template for note and specifying a different attribute set on the fo:block? I guess I'm looking to be able to do something like this:

<xsl:import href="notes.xsl"/>
<xsl:attribute-set name="noteAttrs" merge_with_imported_attr_set="false">
    <xsl:attribute name="font-size">12pt</xsl:attribute>
</xsl:attribute>

I can't switch to an XSLT 3.0 processor immediately, but if there's something new in 3.0 that enables this, I'd love to know about it.

Thanks!

1 Answers1

5

Attribute sets are not very widely used and to answer your question I had to look at the spec to refresh my memory. I don't think there is any way of achieving what you are wanting; you can't really override an attribute set in an importing stylesheet, you can only supplement it. In a well-designed XML vocabulary there is usually an attribute value you can set that is equivalent to omitting the attribute, but if that's not the case then you are stuck.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164