下面是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,'.'),'"')"/>
<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 > $SetFileSize">
<dp:reject>File size exceeded enforced limit</dp:reject>
</xsl:when>
<xsl:otherwise>
<dp:accept/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
DocTypes文件:
<DocTypeMapping>
<DocumentType>
<ContentType>application/octet-stream</ContentType>
<ContentValue>xls</ContentValue>
<ContentValue>xlsx</ContentValue>
<ContentValue>dat</ContentValue>
</DocumentType>
</DocTypeMapping>
有人能看出逻辑是否有问题吗?
答案 0 :(得分:0)
A != B
测试B中是否有一个不等于A的值。如果B包含多个不同的值,则结果将始终为true。你几乎肯定想要not(A = B)
,它测试B中是否没有等于A的值。
另外:您正在测试$fileExtension != $DocCategories/DocTypeMapping/DocumentType/ContentValue/*
。这将查看ContentValue的子元素。但是ContentValue没有任何子元素,因此RHS是一个空集,因此它不包含任何不等于$ fileExtension的值。