【发布时间】:2011-02-24 10:47:28
【问题描述】:
为此我找到了很多引用 Java 和 C 的示例,但是我如何或可以使用 XSL 检查是否存在外部文件。
首先,我意识到这只是一个 sn-p,但它是一个巨大的样式表的一部分,所以我希望它足以显示我的问题。
<!-- Use this template for Received SMSs -->
<xsl:template name="ReceivedSMS">
<!-- Set/Declare "SMSname" variable (local, evaluates per instance) -->
<xsl:variable name="SMSname">
<xsl:value-of select=" following-sibling::Name"/>
</xsl:variable>
<fo:table font-family="Arial Unicode MS" font-size="8pt" text-align="start">
<fo:table-column column-width=".75in"/>
<fo:table-column column-width="6.75in"/>
<fo:table-body>
<fo:table-row>
<!-- Cell contains "speakers" icon -->
<fo:table-cell display-align="after">
<fo:block text-align="start">
<fo:external-graphic src="../images/{$SMSname}.jpg" content-height="0.6in"/>
我想要做的是放在一个“if”语句中,围绕{$SMSname}.jpg 行。那就是:
<fo:block text-align="start">
<xsl:if test="exists( the external file {$SMSname}.jpg)">
<fo:external-graphic src="../images/{$SMSname}.jpg" content-height="0.6in"/>
</xsl:if>
<xsl:if test="not(exists( the external file {$SMSname}.jpg))">
<fo:external-graphic src="../images/unknown.jpg" content-height="0.6in"/>
</xsl:if>
</fo:block>
由于“分组”等原因,我使用的是 XSLT 2.0。我希望这是可以做到的。我更希望它是简单的。
与往常一样,提前感谢您的帮助。 罗
【问题讨论】:
-
好问题 (+1)。简短的回答:目前无法使用纯 XSLT 2.0 完成。长答案和解释:请参阅我的答案。 :)
-
看起来可以使用 EXPath 扩展 - 文件包 (expath.org/spec/file)...
-
我已经为自己完成了,请检查我的答案以获得解决方案。
标签: xslt document external xsl-fo exists