在XSLT中,不能使用xsl:attribute设置value-of的select-attribute的原因是xsl:attribute只能用于设置元素节点的属性,而value-of是一个指令,不是元素节点,因此无法使用xsl:attribute来设置它的属性。
要解决这个问题,可以使用xsl:copy-of指令来复制value-of的结果到一个新的元素节点中,并在该节点上使用xsl:attribute来设置属性。具体步骤如下:
以下是一个示例代码:
<xsl:template match="someElement">
<xsl:variable name="value" select="value-of/someValue" />
<xsl:element name="newElement">
<xsl:attribute name="attributeName">attributeValue</xsl:attribute>
<xsl:copy-of select="$value" />
</xsl:element>
</xsl:template>
在上面的示例中,我们首先将value-of的结果存储到一个名为"value"的变量中。然后,我们使用xsl:element创建一个名为"newElement"的新元素节点,并使用xsl:attribute设置其属性。最后,我们使用xsl:copy-of将变量"value"中的结果复制到新元素节点中。
这样,我们就可以通过创建一个新的元素节点来设置value-of的select-attribute的属性值。
领取专属 10元无门槛券
手把手带您无忧上云