<xsl:attribute-set> 的示例

下面的示例创建一个称为 title-style 的命名属性集并在模板规则中使用。

XML 文件 (book.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="attrset.xsl" ?>
<book>
   <chapter>
      <heading>The First Heading</heading>
   </chapter>
   <chapter>
      <heading>The Next Heading</heading>
   </chapter>
</book>

XSLT 文件 (attrset.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">

<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>

</xsl:stylesheet>

输出

以下是格式化输出:

以下是处理器输出,为了清楚起见,增加了分行符。

<?xml version="1.0"?>
<fo:block font-size="12pt" 
          font-weight="bold" 
          quadding="start" 
          xmlns:fo="http://www.w3.org/1999/XSL/Format">
The First Heading
</fo:block>
<fo:block font-size="12pt" 
          font-weight="bold" 
          quadding="start" 
          xmlns:fo="http://www.w3.org/1999/XSL/Format">
The Next Heading
</fo:block>

请参见

参考

<xsl:attribute> 元素

<xsl:element> 元素

<xsl:copy> 元素