gpt4 book ai didi

xslt - XSLT 模板中的超链接

转载 作者:行者123 更新时间:2023-12-03 20:31:10 29 4
gpt4 key购买 nike

我正在尝试使用 XML 信息和 XSLT 模板创建超链接。这是 XML 源代码。

<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”标签的超链接。

在个股中,标准普尔指数中涨幅最大的股票。 500 家是 Eastman Kodak Co 和 Huntington Bancshares Inc。

这是我现在正在使用的模板。我可以显示文本,但不能显示超链接。
<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"由于某种原因没有被实例化。有没有人对我如何使这项工作有任何想法?

编辑:在查看了一些答案后,它仍然无法在我的整个应用程序中工作。

我从我的主模板中调用 smartText 模板

使用以下语句...
<xsl:value-of select="marketSummaryModuleData/smartText"/>   

这也可能是问题的一部分吗?

谢谢

沙恩

最佳答案

要么移动xsl:attribute在任何 child 之前,或使用 attribute value template .

<xsl:template match="smartTextLink">
<a href="{@smartTextRic}">
<xsl:apply-templates/>
</a>
</xsl:template>

来自 creating attributes XSLT 1 规范的部分:

The following are all errors:

  • Adding an attribute to an element after children have been added to it; implementations may either signal the error or ignore the attribute.

关于xslt - XSLT 模板中的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/706314/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com