如何使用XSL检查外部文件的存在

如何使用XSL检查外部文件的存在

本文介绍了如何使用XSL检查外部文件的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了很多为此引用Java和C的示例,但是我如何或者可以使用XSL检查外部文件的存在.

首先,我意识到这只是一个摘要,但这是一个巨大的样式表的一部分,所以我希望它足以显示我的问题.

    <!-- 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"/>

我想做的是放在语句中,代替{$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.我希望这是可以做的.我希望它更简单.

一如既往,在此先感谢您的帮助.LO

解决方案

否,这不能使用XSLT 2.0/XPath 2.0来完成.

XSLT 2.0函数 unparsed-text-available( ) 仅适用于查找文本文件,即使存在带有指定URI的文本文件,此函数也可能返回false(),因为它还必须读取文件内容并检查是否仅包含允许的字符.

来自 规范 :

"unparsed-text-available函数确定是否对具有相同参数的unparsed-text-function进行调用是否会返回字符串.

如果第一个参数为空序列,则该函数返回false.如果第二个参数为空序列,则该函数的行为就像省略了第二个参数一样.

在其他情况下,如果对具有相同参数的未分析文本的调用成功,则该函数返回true;如果对具有相同参数的未分析文本的调用将因不可恢复的动态错误而失败,则该函数返回false. >

注意:

这要求未解析的文本可用功能实际上应尝试读取URI标识的资源,并检查其是否正确编码并且不包含XML中无效的字符."

引号结尾.

I've found a lot of examples that reference Java and C for this, but how do I, or can I, check for the existence of an external file with XSL.

First, I realize that this is only a snippet, but it's part of a huge stylesheet, so I'm hoping it's enough to show my issue.

    <!-- 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"/>

What I'd like to do, is put in an "if" statement, surronding the {$SMSname}.jpg line. That is:

                     <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>

Because of "grouping", etc., I'm using XSLT 2.0. I hope that this is something that can be done. I hope even more that it's something simple.

As always, thanks in advance for any help.LO

解决方案

No, this cannot be done using XSLT 2.0/XPath 2.0.

The XSLT 2.0 function unparsed-text-available() is only suitable for locating text files and even if a text file with the specifies URI exists this function may return false(), because it also must read the contents of the file and check that it only contains allowed characters.

From the spec:

"The unparsed-text-available function determines whether a call on the unparsed-text function with identical arguments would return a string.

If the first argument is an empty sequence, the function returns false. If the second argument is an empty sequence, the function behaves as if the second argument were omitted.

In other cases, the function returns true if a call on unparsed-text with the same arguments would succeed, and false if a call on unparsed-text with the same arguments would fail with a non-recoverable dynamic error.

Note:

This requires that the unparsed-text-available function should actually attempt to read the resource identified by the URI, and check that it is correctly encoded and contains no characters that are invalid in XML"

End of quotation.

这篇关于如何使用XSL检查外部文件的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:54