【问题标题】:Getting the failed-assert from the sch file从 sch 文件中获取失败的断言
【发布时间】:2019-12-22 00:46:27
【问题描述】:

我有一个 PEPPOL 网站提供的 .sch 文件:http://docs.peppol.eu/poacc/billing/3.0/files/PEPPOL-EN16931-UBL.sch,我们需要将其转换为 .xsl。我们使用名为 oXygen 的工具完成了转换。

这是从 .sch 中截取的生成 [BR-S-06]

<rule context="cac:AllowanceCharge[cbc:ChargeIndicator=false()]/cac:TaxCategory[normalize-space(cbc:ID)='S'][cac:TaxScheme/normalize-space(upper-case(cbc:ID))='VAT']">
      <assert id="BR-S-06" flag="fatal" test="(cbc:Percent) > 0">[BR-S-06]-In a Document level allowance (BG-20) where the Document level allowance VAT category code (BT-95) is "Standard rated" the Document level allowance VAT rate (BT-96) shall be greater than zero.</assert>
    </rule>

这就是我期望规则显示为的方式:

<!--ASSERT -->
<xsl:choose>
  <xsl:when test="@listID = 'UNCL1001'"/>
  <xsl:otherwise>
    <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" test="@listID = 'BR-S-06'">
      <xsl:attribute name="id">BR-S-06</xsl:attribute>
      <xsl:attribute name="flag">fatal</xsl:attribute>
      <xsl:attribute name="location">
        <xsl:apply-templates select="." mode="schematron-select-full-path"/>
      </xsl:attribute>
      <svrl:text>[BR-S-06]-In a Document level allowance (BG-20) where the Document level allowance VAT category code (BT-95) is "Standard rated" the Document level allowance VAT rate (BT-96) shall be greater than zero.</svrl:text>
    </svrl:failed-assert>
  </xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="@*|*" mode="M7"/>

这是它的实际显示方式:

    <!--ASSERT -->
  <xsl:choose>
     <xsl:when test="(cbc:Percent) &gt; 0"/>
     <xsl:otherwise>
        <xsl:message xmlns:iso="http://purl.oclc.org/dsdl/schematron">
           <xsl:text>[BR-S-06]-In a Document level allowance (BG-20) where the Document level allowance VAT category code (BT-95) is "Standard rated" the Document level allowance VAT rate (BT-96) shall be greater than zero.</xsl:text>
        </xsl:message>
     </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="@*|node()" mode="M10"/>

我希望看到 failed-assert 元素,因为它还包含 id/flag/location 而不是我当前得到的消息。

要使用 Saxon 运行验证,我们有以下代码:

public static Dictionary<string, List<ValidationResult>> ValidateXML(string xslTemplate, string xslName, XmlDocument document)
        {
            Dictionary<string, List<ValidationResult>> resultToReturn = new Dictionary<string, List<ValidationResult>>();

            XmlNamespaceManager xmlNamespacesForDocument = GetAllNamespaces(document);
            var transformAssertFailed = new List<ValidationResult>();
            var processor = new Processor();
            var compiler = processor.NewXsltCompiler();
            var executable = compiler.Compile(new MemoryStream(Encoding.UTF8.GetBytes(xslTemplate)));
            var destination = new DomDestination();

            MemoryStream xmlStream = new MemoryStream();
            document.Save(xmlStream);
            xmlStream.Position = 0;
            using (xmlStream)
            {
                var transformer = executable.Load();

                transformer.SetInputStream(xmlStream, new Uri("file:///C:/"));
                transformer.Run(destination);
            }
            return resultToReturn;
        }

我不确定这里出了什么问题,可能是我开始使用的 .sch 文件,或者可能是 .sch 到 .xsl 的转换器。

【问题讨论】:

  • 有多个用 XSLT 编写的 Schematron 处理器(即一组将 Schematron 模式转换为一组 XSLT 规则的样式表)。您没有告诉我们您正在使用哪种 Schematron 处理器。也许您的预期输出基于一个,而您的实际输出基于另一个?

标签: schema xslt-2.0 saxon schematron oxygenxml


【解决方案1】:

我已经在 oXygen 表单 here 上发布了同样的问题,我的问题得到了解答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 2017-08-07
    相关资源
    最近更新 更多