xsl:attribute-set

Syntax

<xsl:attribute-set>
     <xsl:attribute> *
</xsl:attribute-set>


Postition

Top-Level Element


Attribute
Bezeichnung Wert Bedeutung
name QName Name des Attribut-Sets
use-attribute-sets list-of-QNames Liste von Attribut-Sets, die in dem definierten Set verwendet werden

<xsl:attribute-set>

definiert einen Set, das aus einer Ansammlung von Attributen besteht, die mit Hilfe der Anweisung <xsl:attribute> festgelegt werden. Bereits erzeugte Attribut-Sets können mit Hilfe des Attributs [use-attribute-sets] verwendet werden. Ist ein Attribut mehrmals definiert worden, wird der Wert der letzten Definition übernommen.

Einem beliebigen Element können die Attribute mit Hilfe des Attributs [xsl:use-attribute-sets] zugewiesen werden. Die Instuktionen <xsl:element> und <xsl:copy> können das Set verwenden, um mehrere Attributknoten gleichzeitig an der aktuellen Position des Output-Dokuments zu erzeugen.


Definition

XSLT Kapitel 7.1.4


Beispiel 1

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>
    
<xsl:attribute-set name="default-table">
     <xsl:attribute name="BORDER">0</xsl:attribute>
     <xsl:attribute name="CELLSPACING">0</xsl:attribute>
     <xsl:attribute name="CELLPADDING">0</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="aqua-table" use-attribute-sets="default-table">
     <xsl:attribute name="BGCOLOR">AQUA</xsl:attribute>
     <xsl:attribute name="BORDER">1</xsl:attribute>
</xsl:attribute-set>    

<xsl:attribute-set name="white-cell">
     <xsl:attribute name="BGCOLOR">WHITE</xsl:attribute>
</xsl:attribute-set>

<xsl:template match="/">
     <HTML>
          <HEAD>
               <TITLE>Element: &lt;xsl:attribute-set&gt; / Beispiel 01</TITLE>
          </HEAD>
          <BODY>
               <xsl:apply-templates select="shop"/>
          </BODY>
     </HTML>
</xsl:template>

<xsl:template match="shop">
     <xsl:element name="TABLE" use-attribute-sets="aqua-table">
          <TR>
               <TH WIDTH="150">Abteilung:</TH>
               <TH WIDTH="100">Artikel:</TH>
               <TH WIDTH="100">Preis:</TH>
          </TR>
          <xsl:apply-templates select="order/product"/>
     </xsl:element>
</xsl:template>

<xsl:template match="product">
     <TR>
          <TD><xsl:value-of select="@department"/></TD>
          <TD><xsl:value-of select="name"/></TD>
          <TD ALIGN="RIGHT" xsl:use-attribute-sets="white-cell">
               <xsl:value-of select="price"/>
               <xsl:text> </xsl:text>
               <xsl:value-of select="currency"/>
          </TD>
     </TR>
</xsl:template>

</xsl:stylesheet>


Beispiel 2

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>
    
<xsl:attribute-set name="product-info">
     <xsl:attribute name="name">
          <xsl:value-of select="name"/>
     </xsl:attribute>
     <xsl:attribute name="id-nr">
          <xsl:value-of select="id"/>
     </xsl:attribute>
</xsl:attribute-set>

<xsl:template match="/">
     <xsl:processing-instruction name="xml-stylesheet">
          <xsl:text>href="order.css" type="text/css"</xsl:text>
     </xsl:processing-instruction>
     <order>
          <xsl:apply-templates select="shop"/>
     </order>
</xsl:template>

<xsl:template match="shop">
     <xsl:copy-of select="customer"/>
     <xsl:apply-templates select="order/product"/>
</xsl:template>

<xsl:template match="product">
     <xsl:copy use-attribute-sets="product-info">
          <price>
               <xsl:value-of select="price"/>
               <xsl:text> </xsl:text>
               <xsl:value-of select="currency"/>
          </price>
          <amount>
               <xsl:value-of select="amount"/>
          </amount>
     </xsl:copy>
</xsl:template>

</xsl:stylesheet>


© 2001 by Timo Schäfer