相关疑难解决方法(0)

如何在XSLT中处理嵌入式XML标记?

我正在使用XSLT将XML转换为HTML.我无法弄清楚如何处理嵌入式XML节点的格式化.例如,假设我有XML元素:

<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>

但是,在XLST期间,<i>标记会被忽略,因此"星球大战"在HTML输出中不是斜体.是否有一种相对简单的方法来解决这个问题?

的test.xml:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
    <favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>
Run Code Online (Sandbox Code Playgroud)

test.html.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" omit-xml-declaration="yes" />
    <xsl:template match="/">
      <html>
        <head />
          <body>
            <ul>
                <xsl:for-each select="favoriteMovies/favoriteMovie">
                    <li><xsl:value-of select="." /></li>
                </xsl:for-each>
            </ul>
          </body>
      </html>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

html xml xslt formatting

13
推荐指数
1
解决办法
7426
查看次数

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)

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

谢谢

巴蒂尔

xslt

4
推荐指数
2
解决办法
3505
查看次数

标签 统计

xslt ×2

formatting ×1

html ×1

xml ×1