【发布时间】:2021-06-26 14:18:36
【问题描述】:
我正在尝试生成一个报告来检查@href 值是否实际上引用了现有文件。 file:exists() 函数非常适合检查 XML 文件是否存在。但是,当外部文件是图像时,例如jpg, png, etc...这个函数报错:
1 字节 UTF-8 序列的字节 1 无效。
这是我目前所拥有的:
<xsl:template match="*[@href]">
<xsl:variable name="resPath" select="resolve-uri( @href, base-uri() )"/>
<xsl:variable name="check">
<xsl:choose>
<xsl:when test="self::image">
<!-- do something here that results in a boolean value. file:exists() does not work for images-->
</xsl:when>
<xsl:otherwise>
<!-- this works for xml files -->
<xsl:value-of select="file:exists($resPath)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$check = true()">
<li>
<span><xsl:value-of select="@href"/></span><span style="padding-left:5px">Good</span>
</li>
</xsl:when>
<xsl:otherwise>
<li style="background-color:#ffcccc" >
<span><xsl:value-of select="@href"/></span><span style="padding-left:5px">Bad</span>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我正在使用 XSLT 2.0 和 Saxon-PE 9.8.0.12。 任何帮助将不胜感激。
【问题讨论】:
-
我尝试了带有
.jpg文件的EE 9.8.0.12,但没有收到该错误。