English | Français | Deutsch | Magyar | >> 中文 << | Polski ZVON > Tutorials > XSLT Tutorial
>> 页 23 << | 上一条 | 下一条 | 目录 | 元素索引

xsl:attribute 在处理的同时生成元素。它在其包含的元素内创建属性。

XSLT stylesheet 1

XML源码
<source>

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

</source>

输出
<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察看
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>