警告:无法识别的元素 xsl:variable 在线 运行 saxon 但不在 Oxygen 中,为什么?

Warning: unrecognized element xsl:variable online running saxon but not in Oxygen, why?

我有一个类似这样的 schematron 文件(尽可能简单)

    <sch:pattern id="TDOP_0400">
            <sch:rule context="//tekst:Kop">
                 <xsl:variable name="CONDITION"> 
                        <xsl:value-of select="tekst:Label and tekst:Opschrift and tekst:Nummer"/>
                 </xsl:variable>
            </sch:rule>
    </sch:pattern>

当我在 Oxygen 中 运行 它时,它 运行 没问题,但是当我从命令行 运行 它时,我得到一个错误。 这是我的命令行命令:

$ java -cp ../saxon9.9.1.5/saxon9he.jar net.sf.saxon.Transform -t -s:tpod0400.sch -xsl:../saxon9.9.1.5/iso_svrl_for_xslt2.xsl -o:tpod0400.xsl

这是错误消息,我在每个 xsl:variable 行得到它:

Warning: unrecognized element xsl:variable

在命令中添加"allow-foreign=true":

$ java -cp ../saxon9.9.1.5/saxon9he.jar net.sf.saxon.Transform -t -s:tpod0400.sch -xsl:../saxon9.9.1.5/iso_svrl_for_xslt2.xsl -o:tpod0400.xsl allow-foreign=true

"allow-foreign"是iso_svrl_for_xslt2.xsl中的一个参数,在样式表中记录如下:

Pass non-Schematron elements and rich markup to the generated stylesheet

xsl:variable 是一个非 Schematron 元素,除非 allow-foreign=true.

除外

最佳和最安全的做法是将 sch(schematron)与 xslt 代码分开。将 sch-code 保留在规则内,如果您需要 xslt-functionality,则通过对 xslt-code 的函数调用中断,然后 return 函数的结果返回到 sch-code,然后继续sch-处理。

如此简短:切勿在一个编程上下文中混用 sch 和 xslt,这样您将永远安全。

我有一个例子,不管它做什么或它是做什么用的,它在这里演示如何分解一个 sch-context 来调用一些 xslt 代码,然后 return 回到sch 上下文:

<sch:pattern id="TPOD_0520">
    <sch:rule context="//tekst:Hoofdstuk/tekst:Titel">
        <sch:let name="APPLICABLE"
            value="$SOORT_REGELING = $OP or $SOORT_REGELING = $OV or $SOORT_REGELING = $WV"/>
        <sch:let name="hoofdstuk" value="string(../tekst:Kop/tekst:Nummer)"/>
        <sch:let name="titel" value="string(tekst:Titel/tekst:Kop/tekst:Nummer)"/>

<!-- Below is the break-out to XSLT, and the value coming from the function is used in the sch-code -->

        <sch:let name="volgorde" value="foo:volgordeTPOD_0520($titel, .)"/>
        <sch:let name="CONDITION" value="string-length($volgorde) = 0"/>
        <sch:assert test="($APPLICABLE and $CONDITION) or not($APPLICABLE)"> 
            TPOD_0520: Als tussen Hoofdstuk en Afdeling Titel voorkomt dan moet de nummering van Afdelingen beginnen met het samengestelde nummer van de Titel waarin de Afdeling voorkomt, gevolgd door een punt. (betreft hoofdstukken, titels, afdelingen):  <xsl:value-of select="$hoofdstuk"/>: <sch:value-of select="$titel"/>: <sch:value-of select="substring($volgorde,1,string-length($volgorde)-2)"/></sch:assert>
    </sch:rule>
</sch:pattern>

<xsl:function name="foo:volgordeTPOD_0520">
    <xsl:param name="titel" as="xs:string"/>
    <xsl:param name="context" as="node()"/>
    <xsl:variable name="volgorde">
        <xsl:for-each select="$context/tekst:Afdeling">
            <xsl:if test="not(string(tekst:Kop/tekst:Nummer)=concat($titel, '.', string(position())))">
                <xsl:value-of select="concat(string(tekst:Kop/tekst:Nummer),', ')"/>
            </xsl:if>
        </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="$volgorde"/>
</xsl:function>