XSLT模板中的超链接

Gri*_*are 4 xslt

我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

我希望输出看起来像这样,公司名称是基于Xml中"smartTextLink"标签的超链接.

在个股中,S&P的涨幅最大.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>      
Run Code Online (Sandbox Code Playgroud)

我尝试了多种变体,试图让超链接正常工作.我认为模板匹配="smartTextLink"由于某种原因没有被实例化.有没有人对如何使这项工作有任何想法?

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

我在我的主模板中调用了smartText模板

使用以下声明......

<xsl:value-of select="marketSummaryModuleData/smartText"/>   
Run Code Online (Sandbox Code Playgroud)

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

谢谢

巴蒂尔

Pet*_*ham 6

移动xsl:attribute任何子项之前,或使用属性值模板.

<xsl:template match="smartTextLink">
    <a href="{@smartTextRic}">
        <xsl:apply-templates/>
    </a> 
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

从XSLT 1规范的创建属性部分:

以下是所有错误:

  • 添加子元素后,向元素添加属性; 实现可以发出错误信号或忽略属性.


mar*_*c_s 5

试试这个 - 为我工作:

<xsl:template match="smartText">
    <p class="smartText">
      <xsl:apply-templates/>
    </p>
  </xsl:template>

  <xsl:template match="smartTextLink">
    <a>
      <xsl:attribute name="href">
        <xsl:value-of select="@smartTextRic"/>
      </xsl:attribute>
      <xsl:value-of select="text()"/>
    </a>
  </xsl:template>
Run Code Online (Sandbox Code Playgroud)

特技是 - <xsl:attribute>首先,在你做任何其他处理之前.