在我的XSLT文件中,我有以下内容:
<input type="button" value= <xsl:value-of select="name">>
Run Code Online (Sandbox Code Playgroud)
这是一个错误,因为它违反了XML规则.
我真正想要的是从HTML输出中分配给'value'参数的XML文件中获取值.我该怎么做呢?谢谢
<xsl:element name="input">
<xsl:attribute name="type">button</xsl:attribute>
<xsl:attribute name="value" select="name">
</xsl:element>
Run Code Online (Sandbox Code Playgroud)
优秀的HTML/XSL参考
value="{name}"
Run Code Online (Sandbox Code Playgroud)
请参见http://www.w3.org/TR/xslt#attribute-value-templates
编辑:将{$ name}更改为{name}
它根本不需要使用xsl:element
; 我不知道为什么有这么多人提出这个建议.这将有效:
<input type="button">
<xsl:attribute name="value">
<xsl:value-of name="name"/>
</xsl:attribute>
</input>
Run Code Online (Sandbox Code Playgroud)
...但更好的是使用属性值模板:
<input type="button" value="{name}"/>
Run Code Online (Sandbox Code Playgroud)