You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将ISO XSL转换为SVRL XSL的解决方案咨询

Converting ISO-Style Schematron XSL to SVRL XSL for Schematron Validation

Got it, let's break down exactly how to convert your ISO-formatted Schematron XSL into SVRL-compliant XSL based on the examples you shared. The core goal is to replace simple xsl:message error outputs with proper SVRL elements that Schematron validation tools expect, while preserving all your original validation logic.

Key Conversion Steps

Here are the critical changes you'll need to apply to each template and assertion:

  • Add a <svrl:fired-rule> at the start of your template
    This tells Schematron tools that the rule for the matched context has been triggered. Include the context attribute matching your template's match value, and the SVRL namespace.

  • Replace <xsl:message> with <svrl:failed-assert>
    For each assertion failure case (the xsl:otherwise block), swap out the xsl:message with a svrl:failed-assert element. Add a test attribute set to the same expression used in the corresponding xsl:when test.

  • Include the location attribute for failed assertions
    Use the schematron-select-full-path mode to generate a precise path to the invalid node, which simplifies debugging. This is done via an xsl:attribute that applies templates to the current node in that mode.

  • Wrap error text in <svrl:text>
    Move your error message text from xsl:text into svrl:text inside the failed-assert element.

  • Expand xsl:apply-templates to include all node types
    Update the select attribute to cover comments and processing instructions (along with attributes and elements) to ensure full traversal of the XML document.

  • Ensure consistent mode names
    Make sure the mode value in your template and xsl:apply-templates matches (e.g., switch from M23 to M20 as in your SVRL example, or keep it consistent if using a custom mode name).

Converted Example (From Your ISO XSL)

Here's how your original ISO template translates to SVRL-compliant XSL, following all the above steps:

<xsl:template match="sh:StandardBusinessDocument" priority="1000" mode="M20">
  <svrl:fired-rule context="sh:StandardBusinessDocument" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"/>
  
  <!-- ASSERT: sh:StandardBusinessDocumentHeader is required -->
  <xsl:choose>
    <xsl:when test="sh:StandardBusinessDocumentHeader"/>
    <xsl:otherwise>
      <svrl:failed-assert test="sh:StandardBusinessDocumentHeader" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
        <xsl:attribute name="location">
          <xsl:apply-templates mode="schematron-select-full-path" select="."/>
        </xsl:attribute>
        <svrl:text>sh:StandardBusinessDocumentHeader is required.</svrl:text>
      </svrl:failed-assert>
    </xsl:otherwise>
  </xsl:choose>
  
  <!-- ASSERT: ef:Package is required -->
  <xsl:choose>
    <xsl:when test="ef:Package"/>
    <xsl:otherwise>
      <svrl:failed-assert test="ef:Package" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
        <xsl:attribute name="location">
          <xsl:apply-templates mode="schematron-select-full-path" select="."/>
        </xsl:attribute>
        <svrl:text>ef:Package is required.</svrl:text>
      </svrl:failed-assert>
    </xsl:otherwise>
  </xsl:choose>
  
  <!-- ASSERT: xsi:schemaLocation must contain PackageProxy_1_2.xsd -->
  <xsl:choose>
    <xsl:when test="contains(@xsi:schemaLocation,'PackageProxy_1_2.xsd')"/>
    <xsl:otherwise>
      <svrl:failed-assert test="contains(@xsi:schemaLocation,'PackageProxy_1_2.xsd')" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
        <xsl:attribute name="location">
          <xsl:apply-templates mode="schematron-select-full-path" select="."/>
        </xsl:attribute>
        <svrl:text>sh:StandardBusinessDocument xsi:schemaLocation must be 'PackageProxy_1_2.xsd'</svrl:text>
      </svrl:failed-assert>
    </xsl:otherwise>
  </xsl:choose>
  
  <!-- ASSERT: Invoice element with non-empty xsi namespace -->
  <xsl:choose>
    <xsl:when test="not(name()= 'Invoice') or string-length(normalize-space(string(namespace::xsi))) != 0"/>
    <xsl:otherwise>
      <svrl:failed-assert test="not(name()= 'Invoice') or string-length(normalize-space(string(namespace::xsi))) != 0" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
        <xsl:attribute name="location">
          <xsl:apply-templates mode="schematron-select-full-path" select="."/>
        </xsl:attribute>
        <svrl:text>Invoice element and xmlns:xsi attribute with no null values.</svrl:text>
      </svrl:failed-assert>
    </xsl:otherwise>
  </xsl:choose>
  
  <xsl:apply-templates mode="M20" select="@*|*|comment()|processing-instruction()"/>
</xsl:template>

Additional Notes

  • To avoid repeating the SVRL namespace declaration on every element, declare it once at the root of your XSLT document (e.g., on the xsl:stylesheet element):
    <xsl:stylesheet xmlns:svrl="http://purl.oclc.org/dsdl/svrl" ...>
    
  • Ensure the schematron-select-full-path mode template exists in your XSLT—this is a standard Schematron helper template that generates the XPath path to a node. If you don't have it, you'll need to include it (it’s typically part of standard Schematron XSLT libraries).

内容的提问来源于stack exchange,提问作者Tester3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 09:57:40