XSLT 不是在"when"条件下比较多个值?



下面是XSL的一部分,我试图根据多个可能的值检查文件扩展名,并检查XML文件中的内容类型,其中我已经有预设值,但由于某种原因,它没有检查第一个条件。我还把xml文件放在

下面
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:swa="http://ws.apache.org/axis2/mtomsample/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inc="http://www.w3.org/2004/08/xop/include" xmlns:dpconfig="http://www.datapower.com/param/config" extension-element-prefixes="dp" exclude-result-prefixes="dp dpconfig inc">
<xsl:template match="/">
    <xsl:variable name="manifest" select="dp:variable('var://context/INPUT/attachment-manifest')"/>
    <xsl:variable name="ContType" select="$manifest/manifest/attachments/attachment/header[1]/./value/text()"/>
    <xsl:variable name="ContentType" select="substring-before($ContType,';')"/>
    <xsl:variable name="filename" select="$manifest/manifest/attachments/attachment/header[4]/./value/text()"/>
    <xsl:variable name="fileExtension" select="substring-before(substring-after($filename,'.'),'&quot;')"/>
    <xsl:variable name="File_CD" select="document('local:///FileIntake/Resources/FileServiceConfigData.xml')"/>
    <xsl:variable name="DocCategories" select="document('local:///FileIntake/Resources/DocTypes.xml')"/>
    <xsl:variable name="IncomingFileSize" select="number(dp:variable('var://service/mpgw/request-size'))"/>
    <xsl:variable name="SetFileSize" select="number($File_CD/FileServiceConfig/FileSize)"/>
    <dp:set-variable name="'var://context/var/IncomingFileSize'" value="$IncomingFileSize"/>
    <dp:set-variable name="'var://context/var/SetFileSize'" value="$SetFileSize"/>
    <dp:set-variable name="'var://context/var/ContentType'" value="$ContentType"/>
    <dp:set-variable name="'var://context/var/fileExtension'" value="$fileExtension"/>
    <xsl:choose>
        <xsl:when test="$fileExtension != $DocCategories/DocTypeMapping/DocumentType/ContentValue/*">
            <dp:reject>Wrong FileType</dp:reject>
        </xsl:when>
        <xsl:when test="$ContentType != $DocCategories/DocTypeMapping/DocumentType/ContentType">
            <dp:reject>Unsupported ContenType</dp:reject>
        </xsl:when>
        <xsl:when test="$IncomingFileSize &gt; $SetFileSize">
            <dp:reject>File size exceeded enforced limit</dp:reject>
        </xsl:when>
        <xsl:otherwise>
            <dp:accept/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

doctype文件:

<DocTypeMapping>
<DocumentType>
    <ContentType>application/octet-stream</ContentType>
    <ContentValue>xls</ContentValue>
    <ContentValue>xlsx</ContentValue>
    <ContentValue>dat</ContentValue>
</DocumentType>
</DocTypeMapping>

有人可以看看是否有什么问题的逻辑?

A != B测试B中是否存在不等于a的某个值。如果B包含多个不同的值,则结果将始终为真。您几乎肯定需要not(A = B),它测试B中是否没有等于a的值

也:你正在测试$fileExtension != $DocCategories/DocTypeMapping/DocumentType/ContentValue/*。它会查看ContentValue的子元素。但是ContentValue没有任何子元素,所以RHS是一个空集合,因此它不包含不等于$fileExtension的值。

相关内容

  • 没有找到相关文章

最新更新