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

RE: Help needed in XSD

Subject: RE: Help needed in XSD
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 18 Jul 2005 15:22:36 +0100
xsd minoccurs
In general, processing a schema document correctly is tough, unless you know
that it only uses a small subset of the schema language. For example, it's
not easy to apply all the rules for element wildcards, substitution groups,
derivation by extension, use of named model groups, and so on.

But if we assume that you can extract from the schema a list of element
names indicating the order in which children should appear, then it's
reasonably easy to do the transformation. For example if the list is like
this (in order.xml):

<elementOrder>
  <Type/>
  <Description/>
  <MetalHours/>
  <PaintHours/>
</elementOrder>

then you could do

<xsl:template match="Exception">
  <xsl:for-each select="*">
    <xsl:sort select="count(document('order.xml')/elementOrder/*[name() =
name(current())]/preceding-sibling::*)" type="number"/>
    <xsl:copy-of select="."/>
  </xsl:for-each>
</xsl:template> 

> -----Original Message-----
> From: Lakshmi narayana [mailto:lchintala@xxxxxxxxxxxx] 
> Sent: 18 July 2005 12:03
> To: XSL (E-mail)
> Subject:  Help needed in XSD
> 
> 
> Hi,
> I have an xml file and XSD file. For example consider the 
> following xml and
> xsd files.
> In the XSD file, I mentioned the sequence of elements to 
> appear in the XML.
> But what I need
> is, if they are not in the specified sequence in the xml file, the xml
> should be modified to place them in order.
> For this, do I need to write XSLT or we can acheive it using XSD only.
> Please give the code whther in XSLT or XSD.
> 
> XML file
>  <Exception>
>       <Type>X</Type>
>       <Location><![CDATA[Right/Door Front]]></Location>
>       <Description>Dings No Paint Damage, PDR</Description>
>       <ChargeableFlag>0</ChargeableFlag>
>       <PaintHours>0.0</PaintHours>
>       <PartCost>50.0</PartCost>
>       <RepairHours>0.0</RepairHours>
>       <Total>50.0</Total>
>  </Exception>
> 
> XSD file
> 
> <xs:schema elementFormDefault="qualified" 
> attributeFormDefault="unqualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> 	<xs:element name="Exception">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element name="Type" 
> type="xs:string"/>
> 				<xs:element name="Description" 
> type="xs:string"/>
> 				<xs:element 
> name="ChargeableFlag" type="xs:boolean"/>
> 				<xs:element name="FrameHours" 
> type="xs:decimal" minOccurs="0"/>
> 				<xs:element name="PaintHours" 
> type="xs:decimal" minOccurs="0"/>
> 				<xs:element name="PartCost" 
> type="xs:decimal" minOccurs="0"/>
> 				<xs:element name="MetalHours" 
> type="xs:decimal" minOccurs="0"/>
> 				<xs:element name="RepairHours" 
> type="xs:decimal" minOccurs="0"/>
> 				<xs:element name="Total" 
> type="xs:decimal"/>
> 				<xs:element name="Location" 
> type="xs:string"/>
> 				<xs:element 
> name="ExceptionImage" minOccurs="0" maxOccurs="5">
> 					<xs:complexType>
> 						<xs:all>
> 							
> <xs:element name="FileName" type="xs:string"/>
> 						</xs:all>
> 					</xs:complexType>
> 				</xs:element>
> 			</xs:sequence>
> 		</xs:complexType>
> 	</xs:element>
> </xs:schema>
> 
> Thanks
> Laxmi Narayana

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.