XSLT 模板中的超链接 [英] Hyperlinks within XSLT Templates
问题描述
我正在尝试使用 XML 信息和 XSLT 模板创建超链接.这是 XML 源代码.
I am trying to create hyperlinks using XML information and XSLT templates. Here is the XML source.
<smartText>
Among individual stocks, the top percentage gainers in the S. and P. 500 are
<smartTextLink smartTextRic="http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=HBAN.O">Huntington Bancshares Inc</smartTextLink>
and
<smartTextLink smartTextRic="http://investing.domain.com/research/stocks/snapshot
/snapshot.asp?ric=EK">Eastman Kodak Co</smartTextLink>
.
</smartText>
我希望输出看起来像这样,公司名称是基于 Xml 中smartTextLink"标签的超链接.
I want the output to look like this, with the company names being hyperlinks based on the "smartTextLink" tags in the Xml.
在个股中,标准普尔指数中涨幅最大的股票.500 家是 Eastman Kodak Co 和 Huntington Bancshares Inc.
Among individual stocks, the top percentage gainers in the S.&P. 500 are Eastman Kodak Co and Huntington Bancshares Inc.
这是我现在正在使用的模板.我可以显示文本,但不能显示超链接.
Here are the templates that I am using right now. I can get the text to display, but not the hyperlinks.
<xsl:template match="smartText">
<p class="smartText">
<xsl:apply-templates select="child::node()" />
</p>
</xsl:template>
<xsl:template match="smartTextLink">
<a>
<xsl:apply-templates select="child::node()" />
<xsl:attribute name="href">
<xsl:value-of select="@smartTextRic"/>
</xsl:attribute>
</a>
</xsl:template>
我尝试了多种变体来尝试使超链接正常工作.我认为模板 match="smartTextLink" 由于某种原因没有被实例化.有没有人对我如何使这项工作有任何想法?
I have tried multiple variations to try to get the hyperlinks to work correctly. I am thinking that the template match="smartTextLink" is not being instantiated for some reason. Does anyone have any ideas on how I can make this work?
在查看了一些答案后,它在我的整个应用程序中仍然不起作用.
After reviewing some of the answers, it is still not working in my overall application.
我从我的主模板中调用 smartText 模板
I am calling the smartText template from within my main template
使用以下语句...
<xsl:value-of select="marketSummaryModuleData/smartText"/>
这是否也是问题的一部分?
Could this also be a part of the problem?
谢谢
谢恩
推荐答案
或者将 xsl:attribute
移到任何子级之前,或者使用 属性值模板.
Either move the xsl:attribute
before any children, or use an attribute value template.
<xsl:template match="smartTextLink">
<a href="{@smartTextRic}">
<xsl:apply-templates/>
</a>
</xsl:template>
来自 XSLT 1 规范的创建属性部分:
From the creating attributes section of the XSLT 1 spec:
以下都是错误:
- 在添加子元素后向元素添加属性;实现可能会发出错误信号或忽略该属性.
这篇关于XSLT 模板中的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!