是否可以使用xslt创建扩展的xsd。我从另一个部分得到一个xsd,并希望在xsd中添加一些元素,但我无法让它工作。 xslt是要走的路还是有更好的工具?
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.3.19">
<xs:element name="Message">
<xs:annotation>
<xs:documentation>Root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:choice>
<xs:element ref="addAddress"/>
<xs:element ref="addAddressResponse"/>
<xs:element ref="addEmailAddress"/>
<xs:element ref="addEmailAddressResponse"/>
</xs:choice>
</xs:element>
</xs:schema>
扩展:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.3.19">
<xs:element name="Message">
<xs:annotation>
<xs:documentation>Root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<!-- Extended field -->
<xs:element name="generalResponse" minOccurs="0">
<xs:annotation>
<xs:documentation>This response </xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="plainText" type="xs:string" minOccurs="0"/>
<xs:element name="invalidParameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="errorType" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:choice>
<xs:element ref="addAddress"/>
<xs:element ref="addAddressResponse"/>
<xs:element ref="addEmailAddress"/>
<xs:element ref="addEmailAddressResponse"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
答案 0 :(得分:0)
我用这个解决了它。
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element[@name='Message']/xs:complexType">
<xsl:copy>
<xs:sequence>
<!-- Extended field -->
<xs:element name="generalResponse" minOccurs="0">
<xs:annotation>
<xs:documentation>This response</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="plainText" type="xs:string" minOccurs="0" />
<xs:element name="invalidParameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="errorType" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xsl:apply-templates select="node()" />
</xs:sequence>
</xsl:copy>
</xsl:template>