【发布时间】:2018-05-24 20:18:33
【问题描述】:
我的 XML 文档中有一个元素:<resolution>1920x1080</resolution>。我想使用 XPath 从字符串中获取这两个数字,以便在 Schematron 中使用它们。有什么办法吗?
【问题讨论】:
标签: xml xpath schematron
我的 XML 文档中有一个元素:<resolution>1920x1080</resolution>。我想使用 XPath 从字符串中获取这两个数字,以便在 Schematron 中使用它们。有什么办法吗?
【问题讨论】:
标签: xml xpath schematron
使用 XPath 表达式
substring-before(resolution,'x')
得到'1920'和
substring-after(resolution,'x')
得到'1080'。
【讨论】:
或者,如果您使用的是 XSLT2,则可以使用 tokenize(),它返回一个序列 a 字符串:
tokenize(resolution, 'x')
结果是:
tokenize(resolution, 'x')[1] = '1920'
tokenize(resolution, 'x')[2] = '1080'
【讨论】: