Saxon 过早地评估 xsl:attribute-set [英] Saxon Prematurely Evalutes xsl:attribute-set

查看:44
本文介绍了Saxon 过早地评估 xsl:attribute-set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这涉及使用最新的 Saxon EE 9.8 对 XSLT 转换的输入进行模式感知验证.

我的 XSLT 文件包含以下内容.

一个命名空间和相关的架构定义如下:

<xsl:import-schema namespace="http://www.fpml.org/2005/FpML-4-2" schema-location="/path/to/some_swbml.xsd"/>

符合上述模式的结果文档:

<SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" xsl:use-attribute-sets="ir">生成更多 XML 以供 XSD 验证</SWBML></xsl:result-document>

您会注意到结果文档中的父标签使用了一个属性集xsl:use-attribute-sets="ir".>

属性集定义如下:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><xsl:attribute-set name="ir"><xsl:attribute name="version">4-2</xsl:attribute></xsl:attribute-set></xsl:stylesheet>

这是一个玩具示例,上面的样板是不合理的!

当我使用它时效果很好:

 java net.sf.saxon.Transform -sa -ext:on -it -o:output.xml -xsl:example.xslt

这是意料之中的,因为-sa"只会检查输出的 XML 文档,据我所知.

这不起作用:

java net.sf.saxon.Transform -val:lax -ext:on -it -o:output.xml -xsl:example.xslt

给予:

FORG0001:在元素  上不允许使用属性 @xsl:use-attribute-sets

我的问题是 - 在尝试验证 之前,验证器不应该处理属性集吗?在我看来,它抱怨输出 XML 文档中不允许使用 XSLT 指令,这当然是正确的,但似乎过早地检查.

生成的 XML 是有效的:

如使用-sa"选项进行转换所示.

我不确定这是 XSLT 的限制,还是 Saxon 处理中的错误?感觉我应该可以这样对我!

有什么想法吗?

解决方案

我无法重现此问题.

我运行了这个样式表:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:xs="http://www.w3.org/2001/XMLSchema"exclude-result-prefixes="#all"版本=3.0"><xsl:import-schema namespace="http://www.fpml.org/2005/FpML-4-2"><xs:schema targetNamespace="http://www.fpml.org/2005/FpML-4-2"><xs:element name="SWBML"><xs:complexType><xs:extension base="xs:string"><xs:attribute name="version" type="xs:decimal"/></xs:extension></xs:simpleContent></xs:complexType></xs:element></xs:schema></xsl:import-schema><xsl:template name="xsl:initial-template"><xsl:result-document method="xml" validation="strict"><SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" xsl:use-attribute-sets="ir">生成更多 XML 以供 XSD 验证</SWBML></xsl:result-document></xsl:模板><xsl:attribute-set name="ir"><xsl:attribute name="version">4.2</xsl:attribute></xsl:attribute-set></xsl:transform>

使用命令行选项:

-xsl:test.xsl -sa -val:lax -it -t

它运行良好.

在我看来,由于某种原因,您正在验证样式表本身.也许样式表使用结构 document("") 来读取它自己的源代码,在这种情况下,松散的验证将启动并导致此失败.如果这不是解释,请提供更多关于您正在做什么的详细信息.

This relates to schema-aware validation of inputs into an XSLT transformation using latest Saxon EE 9.8.

My XSLT file contains the following.

A namespace and associated schema defined as such:

<xsl:import-schema namespace="http://www.fpml.org/2005/FpML-4-2" schema-location="/path/to/some_swbml.xsd"/>

A result document conforming to the above schema:

<xsl:result-document method="xml" href="{$file}" format="swbml-format" validation="strict">
    <SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" xsl:use-attribute-sets="ir">
        GENERATE SOME MORE XML TO BE VALIDATED BY THE XSD
    </SWBML>
 </xsl:result-document>

You will note that the parent tag in the result document <SWBML> uses an attrribute set xsl:use-attribute-sets="ir".

The attribute set is defined as per below:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:attribute-set name="ir">
        <xsl:attribute name="version">4-2</xsl:attribute>
    </xsl:attribute-set>
</xsl:stylesheet>

This is a toy-example, the boilerplate isn't justified above!

This works fine when I use it with:

 java net.sf.saxon.Transform -sa -ext:on -it -o:output.xml -xsl:example.xslt

This is expected because "-sa" will only check the outputed XML document, as I understand it.

This doesn't work:

java net.sf.saxon.Transform -val:lax -ext:on -it -o:output.xml -xsl:example.xslt

Giving:

FORG0001: Attribute @xsl:use-attribute-sets is not allowed on element <SWBML>

My question is - shouldn't the validator process the attribute sets before trying validate the <SWBML>? It looks to me like it's complaining that an XSLT instruction is not permitted in the output XML document, which is of course true, but it seems to be checking prematurely.

The resulting XML is valid:

<SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" version="4_2">

As demonstrated by transforming with the "-sa" option.

I'm not sure if this is a limitation of XSLT, or a bug in Saxon processing? It feels like I should be able to do this to me!

Any ideas?

解决方案

I haven't been able to reproduce this.

I ran this stylesheet:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all"
  version="3.0">

  <xsl:import-schema namespace="http://www.fpml.org/2005/FpML-4-2">
    <xs:schema targetNamespace="http://www.fpml.org/2005/FpML-4-2">
      <xs:element name="SWBML">
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="xs:string">
              <xs:attribute name="version" type="xs:decimal"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
    </xs:schema>
  </xsl:import-schema>

  <xsl:template name="xsl:initial-template">
    <xsl:result-document method="xml" validation="strict">
      <SWBML xmlns="http://www.fpml.org/2005/FpML-4-2" xsl:use-attribute-sets="ir">
        GENERATE SOME MORE XML TO BE VALIDATED BY THE XSD
      </SWBML>
    </xsl:result-document>
  </xsl:template> 

    <xsl:attribute-set name="ir">
      <xsl:attribute name="version">4.2</xsl:attribute>
    </xsl:attribute-set>


</xsl:transform>

using the command line options:

-xsl:test.xsl -sa -val:lax -it -t

and it ran fine.

It looks to me as if for some reason you are validating the stylesheet itself. Perhaps the stylesheet uses the construct document("") to read its own source code, in which case lax validation will kick in and cause this failure. If that's not the explanation, please provide more detail of exactly what you are doing.

这篇关于Saxon 过早地评估 xsl:attribute-set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆