[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Deleted selected nodes from XSD - howto for Newbie nee

Subject: Deleted selected nodes from XSD - howto for Newbie needed
From: "Michael Lindenau" <michael.lindenau@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Apr 2005 19:18:32 +0200 (CEST)
xsd howto
Hello everyone

I want to delete some unwanted nodes in an XML schema file. Unluckily I'm
only able to copy the whole structure. Whenever I access a specified node to
copy, I get the the text content but not the structure of the node. I think
it is just the right select-expression, that I'm not able to find.

The nodes I want to preserve contain named and unnamed complex types &
simple types and references which should be still in the resulting XSD. The
not needed complex types and referenced elements that were part of the nodes
that are to be deleted shouldn't be in the resulting XSD. Imports, includes
and namespaces are not to be considered.

Above you'll find some example.

Kind regards & thanks in advance

Michael Lindenau
Lvsungen+Ideen

Alejandro Puskin No 1, Portal H, 5C
29011 Malaga
Spanien

phone +49 179  29 28 834
mailto:michael.lindenau@xxxxxxxxxxxxxxxxxxxxxx

"It never hurts to multiply by zero -- it simplifies things a lot." Richard
Keeler

Simplified:

/Root/AllNodes/Header
/Root/AllNodes/Header/Detail
/Root/AllNodes/Nodes/NodeToBeKept1/..
/Root/AllNodes/Nodes/NodeToBeKept2/..
/Root/AllNodes/Nodes/NodeToBeDeleted1/..
/Root/AllNodes/Nodes/NodeToBeDeleted2/..

should result in

/Root/AllNodes/Header
/Root/AllNodes/Header/Detail
/Root/AllNodes/Nodes/NodeToBeKept1/..
/Root/AllNodes/Nodes/NodeToBeKept2/..


Here is the excerpt from my XSLT that doesn't work:
..
<xsl:template
match="/xs:schema/xs:complexType/xs:choice/xs:element/@name['NodeToBeKept1']">   <xsl:copy>
    <xsl:apply-templates select="*|@*" />
   </xsl:copy>
</xsl:template>
..

Here is the complete example schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
	<xs:element name="Root" type="RootType"/>
	<xs:complexType name="RootType">
		<xs:sequence>
			<xs:element name="AllNodes" type="AllNodesType"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="HeaderDetailType">
		<xs:sequence>
			<xs:element name="Detail1" type="Detail1Type" minOccurs="0"/>
			<xs:element ref="Detail2" minOccurs="0"/>
			<xs:element ref="Detail3" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="AllNodesType">
		<xs:sequence>
			<xs:element ref="Header1"/>
			<xs:element ref="Header2"/>
			<xs:element name="Header3" type="NotEmptyString" minOccurs="0"/>
			<xs:element name="Header4" type="HeaderDetailType"/>
			<xs:choice>
				<xs:element name="Nodes" type="NodesType"/>
				<xs:element name="Others" type="OthersType"/>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodesType">
		<xs:choice>
			<xs:element name="NodeToBeKept1" type="NodeToBeKept1Type"/>
			<xs:element name="NodeToBeKept2" type="NodeToBeKept1Type"/>
			<xs:element name="NodeToBeDeleted1" type="NodeToBeDeleted1Type"/>
			<xs:element name="NodeToBeDeleted2" type="NodeToBeDeleted2Type"/>
		</xs:choice>
	</xs:complexType>
	<xs:complexType name="Detail1Type">
		<xs:sequence>
			<xs:element ref="DetailElement1"/>
			<xs:element ref="DetailElement2"/>
			<xs:element name="DetailElement3">
				<xs:simpleType>
					<xs:restriction base="xs:integer">
						<xs:minInclusive value="0"/>
						<xs:maxInclusive value="999"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeKept1Type">
		<xs:sequence>
			<xs:element ref="Node1Element1"/>
			<xs:element ref="Node1Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeKept2Type">
		<xs:sequence>
			<xs:element ref="Node2Element1"/>
			<xs:element ref="Node2Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeDeleted1Type">
		<xs:sequence>
			<xs:element ref="Node3Element1"/>
			<xs:element ref="Node3Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeDeleted2Type">
		<xs:sequence>
			<xs:element ref="Node4Element1"/>
			<xs:element ref="Node4Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:element name="Detail2" type="xs:boolean"/>
	<xs:element name="Detail3" type="NotEmptyString"/>
	<xs:element name="DetailElement1" type="NotEmptyString"/>
	<xs:element name="DetailElement2" type="NotEmptyString"/>
	<xs:element name="Header1" type="NotEmptyString"/>
	<xs:element name="Header2" type="NotEmptyString"/>
	<xs:element name="Node1Element1">
		<xs:simpleType>
			<xs:restriction base="xs:integer">
				<xs:minInclusive value="0"/>
				<xs:maxInclusive value="999"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="Node1Element2" type="NotEmptyString"/>
	<xs:element name="Node2Element1" type="NotEmptyString"/>
	<xs:element name="Node2Element2" type="NotEmptyString"/>
	<xs:element name="Node3Element1" type="NotEmptyString"/>
	<xs:element name="Node3Element2" type="NotEmptyString"/>
	<xs:element name="Node4Element1" type="NotEmptyString"/>
	<xs:element name="Node4Element2" type="NotEmptyString"/>
	<xs:simpleType name="NotEmptyString">
		<xs:restriction base="xs:string">
			<xs:minLength value="1"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:complexType name="OthersType">
		<xs:sequence>
			<xs:element name="Test"/>
			<xs:element name="Test2"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

And here how it should look like after:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
	<xs:element name="Root" type="RootType"/>
	<xs:complexType name="RootType">
		<xs:sequence>
			<xs:element name="AllNodes" type="AllNodesType"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="HeaderDetailType">
		<xs:sequence>
			<xs:element name="Detail1" type="Detail1Type" minOccurs="0"/>
			<xs:element ref="Detail2" minOccurs="0"/>
			<xs:element ref="Detail3" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="AllNodesType">
		<xs:sequence>
			<xs:element ref="Header1"/>
			<xs:element ref="Header2"/>
			<xs:element name="Header3" type="NotEmptyString" minOccurs="0"/>
			<xs:element name="Header4" type="HeaderDetailType"/>
			<xs:choice>
				<xs:element name="Nodes" type="NodesType"/>
				<xs:element name="Others" type="OthersType"/>
			</xs:choice>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodesType">
		<xs:choice>
			<xs:element name="NodeToBeKept1" type="NodeToBeKept1Type"/>
			<xs:element name="NodeToBeKept2" type="NodeToBeKept1Type"/>
		</xs:choice>
	</xs:complexType>
	<xs:complexType name="Detail1Type">
		<xs:sequence>
			<xs:element ref="DetailElement1"/>
			<xs:element ref="DetailElement2"/>
			<xs:element name="DetailElement3">
				<xs:simpleType>
					<xs:restriction base="xs:integer">
						<xs:minInclusive value="0"/>
						<xs:maxInclusive value="999"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeKept1Type">
		<xs:sequence>
			<xs:element ref="Node1Element1"/>
			<xs:element ref="Node1Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="NodeToBeKept2Type">
		<xs:sequence>
			<xs:element ref="Node2Element1"/>
			<xs:element ref="Node2Element2"/>
		</xs:sequence>
	</xs:complexType>
	<xs:element name="Detail2" type="xs:boolean"/>
	<xs:element name="Detail3" type="NotEmptyString"/>
	<xs:element name="DetailElement1" type="NotEmptyString"/>
	<xs:element name="DetailElement2" type="NotEmptyString"/>
	<xs:element name="Header1" type="NotEmptyString"/>
	<xs:element name="Header2" type="NotEmptyString"/>
	<xs:element name="Node1Element1">
		<xs:simpleType>
			<xs:restriction base="xs:integer">
				<xs:minInclusive value="0"/>
				<xs:maxInclusive value="999"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:element>
	<xs:element name="Node1Element2" type="NotEmptyString"/>
	<xs:element name="Node2Element1" type="NotEmptyString"/>
	<xs:element name="Node2Element2" type="NotEmptyString"/>
	<xs:simpleType name="NotEmptyString">
		<xs:restriction base="xs:string">
			<xs:minLength value="1"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:complexType name="OthersType">
		<xs:sequence>
			<xs:element name="Test"/>
			<xs:element name="Test2"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.