如何动态命名属性?
How to dynamically name an attribute?
我正在寻找从 xsl 获取锚标记的自定义属性。
是否可以从 xml 中动态获取属性名称?
这是我尝试过的:
<xsl:attribute name="<xsl:value-of select="id"/>">
<xsl:value-of select="value"/>
</xsl:attribute>
是的,这是可能的。您可以将变量作为 name
值传递。
<xsl:variable name="attributeName" select="id"/>
<xsl:attribute name="{$attributeName}">
<xsl:value-of select="value"/>
</xsl:attribute>
您可以将@Savard 的解决方案简化为
<xsl:attribute name="{id}">
<xsl:value-of select="value"/>
</xsl:attribute>
或者如果您使用的是 XSLT 2.0,
<xsl:attribute name="{id}" select="value"/>
我正在寻找从 xsl 获取锚标记的自定义属性。
是否可以从 xml 中动态获取属性名称?
这是我尝试过的:
<xsl:attribute name="<xsl:value-of select="id"/>">
<xsl:value-of select="value"/>
</xsl:attribute>
是的,这是可能的。您可以将变量作为 name
值传递。
<xsl:variable name="attributeName" select="id"/>
<xsl:attribute name="{$attributeName}">
<xsl:value-of select="value"/>
</xsl:attribute>
您可以将@Savard 的解决方案简化为
<xsl:attribute name="{id}">
<xsl:value-of select="value"/>
</xsl:attribute>
或者如果您使用的是 XSLT 2.0,
<xsl:attribute name="{id}" select="value"/>