Xml 字母数字字符的xslt检查
我想检查字符串是否只包含字母数字字符或“.” 这是我的密码。但它只有在$value与$allowed字符完全匹配时才起作用。我使用XSLT1.0Xml 字母数字字符的xslt检查,xml,xslt,Xml,Xslt,我想检查字符串是否只包含字母数字字符或“.” 这是我的密码。但它只有在$value与$allowed字符完全匹配时才起作用。我使用XSLT1.0 <xsl:template name="GetLastSegment"> <xsl:param name="value" /> <xsl:param name="separator" select="'.'" /> <xsl:variable name="allowed-characters">ABCDE
<xsl:template name="GetLastSegment">
<xsl:param name="value" />
<xsl:param name="separator" select="'.'" />
<xsl:variable name="allowed-characters">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.</xsl:variable>
<xsl:choose>
<xsl:when test="contains($value, $allowed-characters)">
<xsl:call-template name="GetLastSegment">
<xsl:with-param name="value" select="substring-after($value, $separator)" />
<xsl:with-param name="separator" select="$separator" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvxyzo123456789。
我想检查字符串是否只包含字母数字字符或“.”
那就是
<xsl:when test="string-length(translate($value, $allowed-characters, '')) = 0">
<!-- ... -->
</xsl:when>
最后一个函数之后的一般子字符串如下所示:
<xsl:variable name="disallowed-characters" select="translate($value, $allowed-characters, '')" />
<xsl:when test="not($disallowed-characters)">
<!-- ... -->
</xsl:when>
<xsl:template name="substring-after-last">
<xsl:param name="string1" select="''" />
<xsl:param name="string2" select="''" />
<xsl:if test="$string1 != '' and $string2 != ''">
<xsl:variable name="head" select="substring-before($string1, $string2)" />
<xsl:variable name="tail" select="substring-after($string1, $string2)" />
<xsl:variable name="found" select="contains($tail, $string2)" />
<xsl:if test="not($found)">
<xsl:value-of select="$tail" />
</xsl:if>
<xsl:if test="$found">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string1" select="$tail" />
<xsl:with-param name="string2" select="$string2" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
相反的(
最后一个
之前的子字符串)可以在中找到。它们都在XSLT转换期间返回错误:XSLT样式表(可能)包含递归。我的代码中没有递归。检查您的
,您的情况本身是错误的。您是对的。如何在($value,$separator)后执行子字符串并打印结果?我添加了一个通用解决方案,可以从字符串中提取分隔符后的最后一段。
<xsl:variable name="disallowed-characters" select="translate($value, $allowed-characters, '')" />
<xsl:when test="not($disallowed-characters)">
<!-- ... -->
</xsl:when>
<xsl:template name="substring-after-last">
<xsl:param name="string1" select="''" />
<xsl:param name="string2" select="''" />
<xsl:if test="$string1 != '' and $string2 != ''">
<xsl:variable name="head" select="substring-before($string1, $string2)" />
<xsl:variable name="tail" select="substring-after($string1, $string2)" />
<xsl:variable name="found" select="contains($tail, $string2)" />
<xsl:if test="not($found)">
<xsl:value-of select="$tail" />
</xsl:if>
<xsl:if test="$found">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="string1" select="$tail" />
<xsl:with-param name="string2" select="$string2" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>