>> English << | Français | Deutsch | Magyar | 中文 | Polski ZVON > Tutorials > XSLT Tutorial
>> Page 23 << | Prev | Next | Contents | Element Index

xsl:attribute generates elements in time of processing. It creates attribute in the element in which it is enclosed.

XSLT stylesheet 1

XML Source
<source>

<color>blue</color>
<color>navy</color>
<color>green</color>
<color>lime</color>
<color>red</color>

</source>

Output
<TABLE>
  <TR>
     <TD style="color:blue">blue</TD>
  </TR>
</TABLE>

<TABLE>
  <TR>
     <TD style="color:navy">navy</TD>
  </TR>
</TABLE>

<TABLE>
  <TR>
     <TD style="color:green">green</TD>
  </TR>
</TABLE>

<TABLE>
  <TR>
     <TD style="color:lime">lime</TD>
  </TR>
</TABLE>

<TABLE>
  <TR>
     <TD style="color:red">red</TD>
  </TR>
</TABLE>

HTML view
blue
navy
green
lime
red
XSLT stylesheet
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="color">
     <TABLE>
          <TR>
               <TD>
                    <xsl:attribute name="style">
                         <xsl:text>color:</xsl:text>
                         <xsl:value-of select="."/>
                    </xsl:attribute>
                    <xsl:value-of select="."/>
               </TD>
          </TR>
     </TABLE>
</xsl:template>


</xsl:stylesheet>