验证字母数字XSLT



我被验证卡住了。当字符串为空时,我可以进行验证,有长度要求的验证,只有数字的验证,但当输入为具有特殊字符并包含字母数字时。我被卡住了。有人能帮我纠正我的代码需要修复的一侧吗

分枝杆菌:

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_Validate" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<OperationValueRegex>
<xsl:call-template name="values">
<xsl:with-param name="vals" select="//OperationValueRegex/Value"/>
</xsl:call-template>
</OperationValueRegex>
</xsl:template>
<xsl:template name="values">
<xsl:param name="vals"/>
<xsl:choose>
<!-- Validation Number -->
<xsl:when test="fn:tokenize($vals, ' ')[matches(., 'd+')] and string-length($vals) = 8">
<Result1>
<xsl:value-of select="$vals"/>
</Result1>
</xsl:when>
<xsl:when test="$vals = 'NaN' or string-length($vals) != 8">
<Result1>
<Value>
<xsl:value-of select="$vals"/>
</Value>
<notification>input was not valid requirement maximum</notification>
</Result1>
</xsl:when>
<xsl:otherwise>
<Result1>
<Value>
<xsl:value-of select="$vals"/>
</Value>
<notification>Wrong Format</notification>
</Result1>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</localEntry>

请求和预期结果

{
"OperationValueRegex" : {
"Value" : "1234asdv"
}
}

<OperationValueRegex xmlns="http://ws.apache.org/ns/synapse" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<Result1>1234asdv</Result1>
<notification>Wrong Format</notification>
</OperationValueRegex>

感谢

我可以找到验证字母数字的方法

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_Validate" xmlns="http://ws.apache.org/ns/synapse">
<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<OperationValueRegex>
<xsl:call-template name="values">
<xsl:with-param name="vals" select="//OperationValueRegex/Value"/>
</xsl:call-template>
<xsl:call-template name="dates">
<xsl:with-param name="dats" select="//OperationValueRegex/Date"/>
</xsl:call-template>
</OperationValueRegex>
</xsl:template>
<xsl:template name="values">
<xsl:param name="vals"/>
<xsl:choose>
<!-- Validation Number -->
<xsl:when test="fn:matches($vals, '^d+$') and string-length($vals) = 8">
<Result1>
<xsl:value-of select="$vals"/>
</Result1>
</xsl:when>
<xsl:when test="$vals = 'NaN' or string-length($vals) != 8">
<Result1>
<Value>
<xsl:value-of select="$vals"/>
</Value>
<notification>input was not valid requirement maximum</notification>
</Result1>
</xsl:when>
<xsl:when test="fn:matches($vals, '^[a-zA-Z0-9_]*$') and string-length($vals) > 0">
<Value>
<xsl:value-of select="$vals"/>
</Value>
<notification>Wrong Format</notification>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="dates">
<xsl:param name="dats"/>
<xsl:variable name="dateString">
<xsl:value-of select="substring($dats,1,4)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($dats,5,2)"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="substring($dats,7,2)"/>
</xsl:variable>
<RequiredFormat>
<xsl:value-of select="format-date(xs:date($dateString), '[Y]/[M]/[D]')"/>
</RequiredFormat>
<OtherFormat>
<xsl:value-of select="format-date(xs:date($dateString), '[MNn] [D], [Y]')"/>
</OtherFormat>
</xsl:template>
</xsl:stylesheet>
</localEntry>

但当输入具有特殊字符时,我仍然有问题,比如="@+./!~`*%^$((-@";。需要更多关于的帮助

相关内容

  • 没有找到相关文章

最新更新