使用Schematron验证XML

时间:2019-05-28 12:57:28

标签: schematron

我有以下xml,我想解开大于2的ph元素。

输入:(xml)

<ul>
 <li>
   <ph>123</ph>
 </li>
 <li>
   <ph>456</ph>
 </li>
 <li>
   <ph>abc</ph>
 </li>
<li>
<ph>xyz</ph>
</li>
</ul>

O / P:

<ul>
 <li>
   <ph>123</ph>
 </li>
 <li>
   <ph>456</ph>
 </li> 
 <li>
abc
 </li>
<li>
xyz
</li>
</ul>

并且下面的代码无法获得所需的输出

<sch:pattern>
        <sch:rule context="*/ph" role="error">
            <sch:assert test="not(node()>2)" sqf:fix="unwrap"><sch:name/> element not
                allowed</sch:assert>
            <sqf:fix id="unwrap">
                <sqf:description>
                    <sqf:title>unwrap <sch:name/> element</sqf:title>
                </sqf:description>             
                <sqf:replace select="node()"></sqf:replace>
            </sqf:fix>
        </sch:rule>

关于, Shil

2 个答案:

答案 0 :(得分:0)

好吧,假设您的意思是li元素的索引“大于2”,则可以执行以下操作:

  1. 将上下文设置为li[position() gt 2],仅获得位置大于2的li个元素。
  2. 检查是否有ph元素。
  3. sqf:fix元素开始进行li的包装。

解决方案如下:

    <sch:rule context="li[position() gt 2]">
        <sch:report test="ph" sqf:fix="unwrap">ph element not allowed.</sch:report>
        <sqf:fix id="unwrap">
            <sqf:description>
                <sqf:title>Unwrap ph element.</sqf:title>
            </sqf:description>
            <sqf:replace match="ph" select="node()"/>
        </sqf:fix>
    </sch:rule>

另一种方法是将上下文设置为ul。在这种情况下,您只会收到一条错误消息,而QuickFix可以立即进行解包。

答案 1 :(得分:0)

msiexec.exe /i C:\MySetup.msi TRANSFORMS="C:\1033.mst;C:\MyTransform.mst"