我有这个正在运行的 xslt:
<xsl:when test="area_of_expertise">
<div>
<xsl:value-of select="area_of_expertise"/>
</div>
</xsl:when>
但我需要的是:
<xsl:when test="area_of_expertise">
<div id="<xsl:value-of select="area_of_expertise"/>">
<xsl:value-of select="area_of_expertise"/>
</div>
</xsl:when>
然而第二个例子有错误..有人知道为什么吗?
顺便说一句,我们有没有办法改变节点的名称area_of_expertise
into areaOfExperiseLabel
并将其作为 id 插入?我真正需要的输出是这样的:
<div id="areaOfExpertiseLabel">
asasdasdasd
</div>
它出错的原因是它不再是有效的 XML。
做你想做的事:
<xsl:when test="title">
<div id="{title}">
<xsl:value-of select="title"/>
</div>
</xsl:when>
您可以将任何类型的选择器放入 {} 标记内,如果您有复杂的内容,甚至可以引用变量。
<xsl:variable name="some_complex_variable">
<xsl:value-of select="title"/>
</xsl:variable>
<xsl:when test="title">
<div id="{$some_complex_variable}">
<xsl:value-of select="title"/>
</div>
</xsl:when>
第三种冗长的方法是使用 xsl:attribute 动态附加属性:
<xsl:when test="title">
<div>
<xsl:attribute name="id" select="title"/>
</div>
</xsl:when>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)