Share via


Exemple de <xsl:attribute-set>

L'exemple suivant crée un ensemble d'attributs appelé title-style et l'utilise dans une règle de modèle.

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

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

Sortie

Voici les données en sortie formatées :

Voici les données en sortie du processeur ; des sauts de ligne ont été ajoutés pour plus de clarté.

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

Voir aussi

Référence

Élément <xsl:attribute>

Élément <xsl:element>

Élément <xsl:copy>