I need to create links using dynamic values for both the URL and the anchor text.
I have column called URL, which contains URL's, i.e., http://stackoverflow.com, and I have a column called Title, which contains the text for the anchor, i.e., This Great Site.
I figure maybe all I need to do is nest this tags, along with a little HTML to get my desired result:
<a href=">
<xsl:value-of select="@URL">">
<xsl:value-of select="@Title"/>
</xsl:value-of>
</a>
Run Code Online (Sandbox Code Playgroud)
In my head, this would render:
<a href="
http://stackoverflow.com">
This Great Site
</a>
Run Code Online (Sandbox Code Playgroud)
我知道还有更多,但我一直无法清楚地了解我还需要什么。我认为这个问题以前已经解决过,但不是我能理解的方式。我很乐意改进问题的标题以帮助像我这样的菜鸟找到这个项目,并希望得到答案。
任何帮助是极大的赞赏。
如果没有看到您的 XML,很难给出准确的答案,但是您可以在此处使用“属性值模板”来创建href属性。
<a href="{@URL}">
<xsl:value-of select="@Title"/>
</a>
Run Code Online (Sandbox Code Playgroud)
花括号{ }表示要计算的表达式,而不是字面上的输出。
对于复杂的表达式,或者如果您只想为某些条件创建属性,或者使用动态名称,您可以使用xsl:attribute元素,如下所示
<a>
<xsl:attribute name="href">
<xsl:value-of select="@URL"/>
</xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
Run Code Online (Sandbox Code Playgroud)
不过,通常首选属性值模板。