【问题标题】:Convert schema-aware stylesheet转换模式感知样式表
【发布时间】:2019-11-13 03:06:21
【问题描述】:

我有一个模式感知 XSLT 转换效果很好。但是,XSLT 的预期用户可能无法访问架构感知处理器。因此,我想编写一些代码,将我的架构感知XSLT 转换为基本级别的处理器可以使用的 XSLT。

出于我的目的,模式感知结构的使用仅限于匹配模板,即 <xsl:template match="element(*, Candidate)">...</>

我不希望这是一个全自动过程。我想要的是生成一个XSLT,对于XSD 中的每个complexType,都会在指定的浮出水面XSDelement 中找到它的用途。

示例代码:

<xsd:schema xmlns="example.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="example.xsd" elementFormDefault="qualified" version="0.0">
    <xsd:element name="Candidate" type="Candidate"/>
    <xsd:complexType name="Candidate">
        <xsd:sequence>
            <xsd:element name="Code" type="Code" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="Name" type="xsd:string" minOccurs="0"/>
            <xsd:element name="PartyId" type="Code" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Code">
        <xsd:sequence>
            <xsd:element name="Value" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

元素Candidate 的预期输出是这样的:

<complexType_usages>
  <usage complexType="Code" path="Candidate/Code" />
  <usage complexType="Code" path="Candidate/Party" />
</complexType_usages>

【问题讨论】:

    标签: xslt xsd saxon


    【解决方案1】:

    从经过验证的实例开始工作可能比尝试分析架构更简单(只要实例具有足够的代表性)。对于每个元素,输出类型注释(使用 saxon:type-annotation)和路径,然后获取类型/路径对列表,并消除重复和冗余。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 2018-11-14
      • 2011-05-30
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      相关资源
      最近更新 更多