web analytics

xsl:attribute, xsl:attribute-set and xsl:use-attribute-sets in XSLT

Options

codeling 1602 - 6666
@2017-09-26 12:07:32

The xsl:attribute-set element defines a named set of attributes.

The content of the xsl:attribute-set element consists of zero or more xsl:attribute elements that specify the attributes in the set.

Attribute sets are used by specifying a use-attribute-sets attribute on xsl:element, xsl:copy or xsl:attribute-set elements. The value of the use-attribute-sets attribute is a whitespace-separated list of names of attribute sets. Specifying a use-attribute-sets attribute is equivalent to adding xsl:attribute elements for each of the attributes in each of the named attribute sets to the beginning of the content of the element with the use-attribute-sets attribute, in the same order in which the names of the attribute sets are specified in the use-attribute-sets attribute.

Attribute sets can also be used by specifying an xsl:use-attribute-sets attribute on a literal result element. The value of the xsl:use-attribute-sets attribute is a whitespace-separated list of names of attribute sets. The xsl:use-attribute-sets attribute has the same effect as the use-attribute-sets attribute on xsl:element with the additional rule that attributes specified on the literal result element itself are treated as if they were specified by xsl:attribute elements before any actual xsl:attribute elements but after any xsl:attribute elements implied by the xsl:use-attribute-sets attribute. Thus, for a literal result element, attributes from attribute sets named in an xsl:use-attribute-sets attribute will be added first, in the order listed in the attribute; next, attributes specified on the literal result element will be added; finally, any attributes specified by xsl:attribute elements will be added. Since adding an attribute to an element replaces any existing attribute of that element with the same name, this means that attributes specified in attribute sets can be overridden by attributes specified on the literal result element itself.

The following example creates a named attribute set title-style and uses it in a template rule.

<xsl:template match="chapter/heading">
  <fo:block quadding="start" xsl:use-attribute-sets="title-style">
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:attribute-set name="title-style">
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:attribute-set>

 

@2017-09-26 12:49:34

Example of Applying Multiple Attribute Sets

The following XSLT example shows how to define multiple attribute sets and use a space-separated list of attribute set names.

 
 
<xsl:attribute-set name="normal">
  <xsl:attribute name="font-family">Helvetica, sans-serif</xsl:attribute>
  <xsl:attribute name="font-size">14pt</xsl:attribute>
</xsl:attribute-set>
 
<xsl:attribute-set name="alert">
  <xsl:attribute name="background-color">#ffff00</xsl:attribute>
  <xsl:attribute name="color">#ff0000</xsl:attribute>
</xsl:attribute-set>
 
<fo:block xsl:use-attribute-sets="normal alert">
     <xsl:value-of select="@abbreviation"/>
</fo:block>

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com