I have a software generated schema which creates a few
empty elements, e.g. <xsd:sequence/>. I would like to be
able to delete these elements from the schema
post-generation using XSLT.
I've tried using the identity pattern to copy the whole
schema except these rogue elements but I seem to be
getting stuck on how to correctly choose this particular
'sequence' element to ignore during copying.
Assuming you've bound the XML Schema namespace to the xsd
prefix in your transformation:
xsd:sequence[not(*)]
Pavel,
Thanks for your advice, unfortunately, being a total novice it did not
work for me.
Here's my input test schema and xslt that I'm using.
<xsd:schema xmlns:xsd="
http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="TestSchema">
<xsd:annotation>
<xsd:documentation>Comment describing your root element</
xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="VarCharStructure">
<xsd:annotation>
<xsd:documentation>A characteristic that can vary over time. The
time at which the characteristic is recorded is given by the activity
or occurrence of information to which it is linked.</
xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="SuperClassStructure">
<xsd:sequence/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SuperClassStructure">
<xsd:annotation>
<xsd:documentation>Provides a referencable ID element for all class
objects</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="SuperClassURN" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Processed using this XSLT:
<xsl
utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/ <!-- copy through any comments or processing instructions found in
the input schema -->
<xsl:template match="comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
<!-- copy any other elements and associated attributes and values -->
<xsl:template match="*">
<xsl:if test=".//xsd:sequence[not(*)]"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Produces the same output as the input demonstrating my total lack of
understanding of xslt.
best regards,
W.