Saxon Prematurely Evalutes xsl:attribute-set

送分小仙女□ 提交于 2019-12-10 10:52:38

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/50493231/saxon-prematurely-evalutes-xslattribute-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!