今天介绍一下,<xsl:attribute> 元素的使用。有时候我们在使用xslt转换xml时,可能要循环动态生成表单元素,并
根据循环中的某个Id值,指定不同的表单元素的name,或者Id。这个时候<xsl:attribute> 元素就可以发挥作用了。
看看微软对这个元素的解释:
<xsl:attribute> 元素
创建一个属性节点并将其附加到输出元素上。
通过使用 <xsl:attribute> 元素替代属性值模板,可以执行下列操作:
-
计算属性名。
-
在生成属性时使用条件、模板和属性集。
-
将属性添加到 <xsl:copy> 或 <xsl:element> 元素所生成的元素。
例子:
<xsl:attribute
name = "attribute-name"
namespace = "uri-reference">
</xsl:attribute>
name = "attribute-name"
namespace = "uri-reference">
</xsl:attribute>
<IMG>
<xsl:attribute name="src">
<xsl:value-of select="imagenames/imagename" />
</xsl:attribute>
</IMG>
<xsl:attribute name="src">
<xsl:value-of select="imagenames/imagename" />
</xsl:attribute>
</IMG>
输出:
<IMG src=" imagenames/imagename"/>