xsl:value-of在xml属性中的输出结果

Rob*_*und 21 xslt

我有一个XML输入文件,我正在尝试输出调用的结果,如:

<xsl:value-of select="Some/Value"/>  
Run Code Online (Sandbox Code Playgroud)

成为一个属性.

<Output Attribute="Value should be put here"/>
Run Code Online (Sandbox Code Playgroud)

我的问题是,因为我输出XML,XSL处理器不允许我写:

<Output Attribute="<xsl:value-of select="Some/Value"/>">
Run Code Online (Sandbox Code Playgroud)

你是如何做到这一点的?

Dan*_*bić 41

最简单的方法是使用属性值模板,如下所示:

<Output Attribute="{Some/Value}"/>
Run Code Online (Sandbox Code Playgroud)


Phi*_*oss 21

您可以使用xsl:attribute元素:

<Output>
  <xsl:attribute name="Attribute">
    <xsl:value-of select="Some/Value"/>
  </xsl:attribute>
</Output>
Run Code Online (Sandbox Code Playgroud)