我需要测试一个attibute值是否以字母开头.如果不是,我将用"ID_"作为前缀,因此它将是一个有效的id类型的属性值.我目前有以下内容(测试该值不以数字开头 - 我知道这些属性值只会以字母或数字开头),但我希望有更优雅的方式:
<xsl:if test="not(starts-with(@value, '1')) and not(starts-with(@value, '2')) and not(starts-with(@value, '3')) and not(starts-with(@value, '4')) and not(starts-with(@value, '5')) and not(starts-with(@value, '6')) and not(starts-with(@value, '7')) and not(starts-with(@value, '8')) and not(starts-with(@value, '9')) and not(starts-with(@value, '0')) ">
Run Code Online (Sandbox Code Playgroud)
我正在使用XSLT 1.0.提前致谢.
用途:
not(number(substring(@value,1,1)) = number(substring(@value,1,1)) )
Run Code Online (Sandbox Code Playgroud)
或使用:
not(contains('0123456789', substring(@value,1,1)))
Run Code Online (Sandbox Code Playgroud)
最后,这可能是最短的XPath 1.0表达式来验证您的条件:
not(number(substring(@value, 1, 1)+1))
Run Code Online (Sandbox Code Playgroud)