【发布时间】:2014-01-24 09:12:27
【问题描述】:
我想使用我的 xsl 文件在我的 PDF 报告中创建一个标题。如果源文件包含超链接,则应将其呈现为超链接,否则呈现为纯文本。
例如,我的 xml 看起来像:
<a href='http://google.com' target='_blank'>This is the heading </a>"
如果有超链接,它应该显示一个超链接,否则将标题显示为纯文本。 我该怎么做?
在 else 标签下我无法使用下面的代码,请看下面
<xsl:choose>
<xsl:when test="($RTL='true') or ($RTL='True')">
<fo:block wrap-option="wrap" hyphenate="true" text-align="right" font-weight="bold">
<xsl:value-of select="@friendlyname" />
</fo:block>
</xsl:when>
<xsl:otherwise>
<!--<fo:block wrap-option="wrap" hyphenate="true" font-weight="bold">-->
<xsl:template match="a">
<fo:block>
<xsl:choose>
<xsl:when test="@href">
<fo:basic-link>
<xsl:attribute name="external-destination">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:value-of select="@friendlyname" />
</fo:basic-link>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@friendlyname" />
</xsl:otherwise>
</xsl:choose>
</fo:block>
</xsl:template>
<!--<xsl:value-of select="@friendlyname" />-->
<!--</fo:block>-->
</xsl:otherwise>
</xsl:choose>
</xsl:if>
我如何在那里使用它?
【问题讨论】:
-
这是使用
xsl:template元素的错误方式。它不能在otherwise内。所以,现在(即,因为您更新了问题),您的问题与基本链接无关,而是与编写 XSLT 代码的基本规则有关。