xml 将 xsl:value-of 设置为 href 属性和 XSLT 中链接的文本字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2563021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting xsl:value-of into an href attribute and the text field of a link in an XSLT
提问by Josh
How can I set an a href that is both a link to and has the text for a link through an XSLT transformation? Here's what I have so far, which gives me the error "xsl:value-of cannot be a child of the xsl:text element":
如何通过 XSLT 转换设置既是链接又包含链接文本的 href?这是我到目前为止所拥有的,这给了我错误“xsl:value-of 不能是 xsl:text 元素的子元素”:
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="actionUrl"/>
</xsl:attribute>
<xsl:text><xsl:value-of select="actionUrl"/></xsl:text>
</xsl:element>
回答by zneak
<xsl:text>defines a text section in an XSL document. Only real, plain text can go here, and not XML nodes. You only need <xsl:value-of select="actionUrl"/>, which will print text anyways.
<xsl:text>定义 XSL 文档中的文本部分。只有真正的纯文本才能进入这里,而不是 XML 节点。您只需要<xsl:value-of select="actionUrl"/>, 无论如何都会打印文本。
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="actionUrl"/>
</xsl:attribute>
<xsl:value-of select="actionUrl"/>
</xsl:element>
回答by lexicore
You can also do:
你也可以这样做:
<a href="{actionUrl}"><xsl:value-of select="actionUrl"/></a>
回答by Oded
You don't need the xsl:textelement:
你不需要xsl:text元素:
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="actionUrl"/>
</xsl:attribute>
<xsl:value-of select="actionUrl"/>
</xsl:element>

