在此网站http://gskinner.com/RegExr/(这是一个 RegEx 测试网站)上,此正则表达式匹配有效匹配:
[^\x00-\xff]
示例文本:test123 或元件数据不可用
但如果我有这个输入 XML:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<node>test123 或元件数据不可用</node>
</root>
我用 Saxon 9 试试这个 XSLT 2.0 样式表:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root/node">
<xsl:if test="matches(., '[^\x00-\xff]')">
<xsl:text>Text has chinese characters!</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Saxon 9 给了我以下错误输出:
FORX0002: Error at character 3 in regular expression "[^\x00-\xff]": invalid escape sequence
Failed to compile stylesheet. 1 error detected.
如何在 XSLT 2.0 中检查汉字?