模式感知流是否可能?
Is schema-aware streaming possible?
假设我有使用 xs:sequence(而不是 xs:all)的简单模式。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="mynamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="mynamespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="RepeatingElement" type="repeatingElementType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="repeatingElementType">
<xs:sequence>
<xs:element name="FirstElement" type="xs:string"/>
<xs:element name="SecondElement" type="xs:string"/>
<xs:element name="ThirdElement" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
然后我编写一个模式感知转换,它按顺序使用节点。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:n1="mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:mode streamable="yes"/>
<xsl:import-schema namespace="mynamespace" schema-location="sampleSchema.xsd"></xsl:import-schema>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="element(*, n1:repeatingElementType)">
<xsl:value-of select="n1:FirstElement" />
<xsl:value-of select="n1:SecondElement" />
<xsl:value-of select="n1:ThirdElement" />
</xsl:template>
</xsl:stylesheet>
现在,流式引擎(即 SAXON)会抛出错误。
Template rule is declared streamable but it does not satisfy the streamability rules. * There is more than one consuming operand: {xsl:value-of} on line 10, and {xsl:value-of} on line 11
鉴于引擎知道元素可以出现的顺序,难道它不应该能够在分析阶段确定样式-sheet 是可流式传输的吗?
XSLT 3.0 规范中内置并在 Saxon 中实现的流式分析没有考虑可能来自模式知识的任何兄弟顺序知识。它可以在理论上完成,但规则会变得非常复杂以处理除了最简单的情况之外的任何情况。 (例如,考虑样式表中的 xsl:choose
在结构上对应于架构中的 xs:choice
...)工作组早期决定将其排除在范围之外。
假设我有使用 xs:sequence(而不是 xs:all)的简单模式。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="mynamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="mynamespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="RepeatingElement" type="repeatingElementType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="repeatingElementType">
<xs:sequence>
<xs:element name="FirstElement" type="xs:string"/>
<xs:element name="SecondElement" type="xs:string"/>
<xs:element name="ThirdElement" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
然后我编写一个模式感知转换,它按顺序使用节点。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:n1="mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:mode streamable="yes"/>
<xsl:import-schema namespace="mynamespace" schema-location="sampleSchema.xsd"></xsl:import-schema>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="element(*, n1:repeatingElementType)">
<xsl:value-of select="n1:FirstElement" />
<xsl:value-of select="n1:SecondElement" />
<xsl:value-of select="n1:ThirdElement" />
</xsl:template>
</xsl:stylesheet>
现在,流式引擎(即 SAXON)会抛出错误。
Template rule is declared streamable but it does not satisfy the streamability rules. * There is more than one consuming operand: {xsl:value-of} on line 10, and {xsl:value-of} on line 11
鉴于引擎知道元素可以出现的顺序,难道它不应该能够在分析阶段确定样式-sheet 是可流式传输的吗?
XSLT 3.0 规范中内置并在 Saxon 中实现的流式分析没有考虑可能来自模式知识的任何兄弟顺序知识。它可以在理论上完成,但规则会变得非常复杂以处理除了最简单的情况之外的任何情况。 (例如,考虑样式表中的 xsl:choose
在结构上对应于架构中的 xs:choice
...)工作组早期决定将其排除在范围之外。