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