XSL 属性模板的运用

XML中

<home>http://www.planabc.net</home>

如果我们在 XSL 中要调用 home节点的值作为 a 标签的 href 属性值,该如何应对呢?

我们可以通过给 a 标签添加一个属性,具体语法:

<xsl:attribute name="href">http://www.planabc.net</xsl:attribute>

name 属性表示要添加属性的名字,标记包含的内容为要添加属性的值。

根据上面的介绍我们在 XSL 中可以写成这样:

<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="home" /></xsl:attribute>
Index
</xsl:element>

或者:

<a title="">
<xsl:attribute name="href"><xsl:value-of select="home" /></xsl:attribute>
Index
</a>

在 XSL 中还有一个更简单更方便的方法,就是用属性模板,可以直接在 XSL 中这样使用:

<a title="" href="{home}">Index</a>

其中的 {home} 就是属性模板。{home} 等同于 <xsl:value-of select=”home”/>

MSDN 上是这样定义的:

name 属性的值解释为一个属性值模板 — 即计算大括号中的表达式并转换为字符串,与 <xsl:value-of> 中相同。

http://www.cnblogs.com/TerryFeng/archive/2009/07/24/1529818.html


原文地址:https://www.cnblogs.com/HeroBeast/p/1620024.html