【问题标题】:How to separate two numbers from string using XPath如何使用 XPath 将两个数字从字符串中分离出来
【发布时间】:2018-05-24 20:18:33
【问题描述】:

我的 XML 文档中有一个元素:<resolution>1920x1080</resolution>。我想使用 XPath 从字符串中获取这两个数字,以便在 Schematron 中使用它们。有什么办法吗?

【问题讨论】:

    标签: xml xpath schematron


    【解决方案1】:

    使用 XPath 表达式

    substring-before(resolution,'x')
    

    得到'1920'和

    substring-after(resolution,'x')
    

    得到'1080'。

    【讨论】:

      【解决方案2】:

      或者,如果您使用的是 XSLT2,则可以使用 tokenize(),它返回一个序列 a 字符串:

      tokenize(resolution, 'x')

      结果是:

      tokenize(resolution, 'x')[1] = '1920'

      tokenize(resolution, 'x')[2] = '1080'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-06
        • 2014-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多