有没有办法在schematron中传递变量?

时间:2017-01-31 01:48:27

标签: xml xslt xsd xslt-2.0 schematron

我想使用变量来表示我的schematron断言,并在我的验证消息中使用它。例如:

        <rule context="//Profile/User[@name]">
            <assert test="@name = ../business/@owner">User: '----' doesn't exist as a business owner. </assert>
        </rule>

'----'代表用户的名字。有没有办法在schematron中使用变量?

1 个答案:

答案 0 :(得分:3)

您可以使用value-of检索变量或XPath的值:

    <rule context="//Profile/User[@name]">
        <assert test="@name = ../business/@owner">
          User: <value-of select="@name"/> doesn't exist as a business owner.
        </assert>
    </rule>

如果您想引入变量,请使用let

    <rule context="//Profile/User[@name]">
        <let name="userName" value="@name"/>
        <assert test="@name = ../business/@owner">
          User: <value-of select="$userName"/> doesn't exist as a business owner.
        </assert>
    </rule>