XSLT专业站 - 提供xslt和xml相关的资料书籍和教程  
XSLT专业站 - 提供xslt和xml相关的资料书籍和教程
网站地图  收藏本站
首页 | 热门文章 | 精彩实例 | 经典教程 | XSLT语法详解 | 资料下载 | 休闲天地 | 交流论坛
  当前位置:首页>XSLT语法详解>文章内容
XSLT 语法详解: xsl:attribute-set
来源:XSLT.org.cn 作者:XSLT专业站 发布时间:2007-10-27  
XSLT 语法详解: xsl:attribute-set
<xsl:attribute-set>提供在输出文档中创建一组元素属性的功能,可以通过名字引用整个属性组,而不用单个地创建它们。

必需属性:
    name: 该属性定义属性组的名字。

可选属性:
   use-attribute-sets:该属性可以列出属性组中引用的其他一个或多个属性组,如果引用了多个属性组需要用空格隔开它们。使用这个属性可以是一个属性组嵌入另一个属性组,但是如果一个属性组直接或间接地嵌入了自己,将会产品错误。换句话说,如果属性组A内嵌了B,B内嵌C,而C内嵌了A, XSLT解析器将会报告错误。

<xsl:attribute-set>可以包含一个或多个<xsl:attribute>。<xsl:attribute-set>是一个顶级元素,只能作为<xsl:stylesheet>的子元素。

实例:我们用属性组来定义不同的文本字体及大小,并且为了易于区分,我们采用XSL-FO将XML文档转换成PDF文件。
XSLT源码:
<?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:output method="html"/>

  <xsl:attribute-set name="regular-text">
    <xsl:attribute name="font-size">12pt</xsl:attribute>
    <xsl:attribute name="font-family">sans-serif</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="emphasized-text" use-attribute-sets="regular-text">
    <xsl:attribute name="font-style">italic</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="large-text" use-attribute-sets="regular-text">
    <xsl:attribute name="font-size">18pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="space-after.optimum">21pt</xsl:attribute>
  </xsl:attribute-set>

  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master margin-right="75pt" margin-left="75pt"
          page-height="11in" page-width="8.5in"
          margin-bottom="25pt" margin-top="25pt" master-name="main">
          <fo:region-before extent="25pt"/>
          <fo:region-body margin-top="50pt" margin-bottom="50pt"/>
          <fo:region-after extent="25pt"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="standard">
          <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-name="main"
              odd-or-even="any"/>
          </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
      </fo:layout-master-set>
     
      <fo:page-sequence master-name="standard">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="list"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>

  <xsl:template match="list">
    <fo:block xsl:use-attribute-sets="large-text">
      <xsl:value-of select="title"/>
    </fo:block>
    <fo:list-block provisional-distance-between-starts="0.4cm"
      provisional-label-separation="0.15cm">
      <xsl:for-each select="listitem">
        <fo:list-item start-indent="0.5cm" space-after.optimum="17pt">
          <fo:list-item-label>
            <fo:block xsl:use-attribute-sets="regular-text">*</fo:block>
          </fo:list-item-label>
          <fo:list-item-body>
            <fo:block xsl:use-attribute-sets="emphasized-text">
              <xsl:value-of select="."/>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:for-each>
    </fo:list-block>
  </xsl:template>

</xsl:stylesheet>


XML文档为:
<?xml version="1.0"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

转换后的PDF文件为:


标题: XSLT 语法详解: xsl:attribute-set
关键字:XSLT 语法详解 xsl:attribute-set 属性组
上一篇:XSLT 语法详解: xsl:attribute   下一篇:XSLT 实例:使用不同的轴(Axis)
  XSLT语法详解热点文章
·XSLT 语法详解:xsl:apply-impor
·xsl:for-each 语法
·xsl:choose, xsl:when 和 xsl:ot
·xsl:sort 语法
·XSLT 语法详解: xsl:apply-templ
·XSLT 语法详解: xsl:attribute
·xsl:template 和 xsl:apply-temp
·xsl:value-of 语法
·xsl:if 语法
  XSLT语法详解相关文章
·XSLT 语法详解: xsl:attribute
·XSLT 语法详解: xsl:apply-templ
·XSLT 语法详解:xsl:apply-impor
·xsl:sort 语法
·xsl:choose, xsl:when 和 xsl:ot
·xsl:if 语法
·xsl:for-each 语法
·xsl:value-of 语法
·xsl:template 和 xsl:apply-temp
Copyright© 2007 xslt.org.cn All rights reserved.