Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XSLT: Reduce XML to fit Schema

From: "C. Marco" <astralarse@----------.--->
To: NULL
Date: 8/14/2009 6:48:00 AM
Hi all,

I posted this in XSLT group before but maybe you can help me in here,
too. So sorry to everyone who got this question twice because you're
in both groups.

Anyway, I'm pretty unexperienced using XSLT and I have a little
question which I hope can be answered here:
Is there a simple way to reduce an existing XML file to make it fit a
XML Schema?

For example if I have a XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://test/"
         xsi:schemaLocation="http://test/ result.xsd">
   <b>Node B</b>
   <c>Node C</c>
   <m>
      <x>Node X1</x>
      <y>Node Y1</y>
      <z>Node Z1</z>
      <m>
         <x>Node X2</x>
         <y>Node Y2</y>
         <z>Node Z2</z>
      </m>
   </m>
</a>

and I want to create a copy of this file only with the correct nodes
so that it fits a XSD like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:tns="http://test/"
         targetNamespace="http://test/"
         elementFormDefault="qualified"
         attributeFormDefault="unqualified">
   <xs:element name="a">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref="tns:b"/>
            <xs:element ref="tns:m"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:element name="m">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref="tns:x" minOccurs="0"/>
            <xs:element ref="tns:y"/>
            <xs:element ref="tns:m" minOccurs="0"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:element name="b">
      <xs:simpleType>
            <xs:restriction base="xs:string"/>
      </xs:simpleType>
   </xs:element>
   <xs:element name="x">
      <xs:simpleType>
         <xs:restriction base="xs:string"/>
      </xs:simpleType>
   </xs:element>
   <xs:element name="y">
      <xs:simpleType>
         <xs:restriction base="xs:string"/>
      </xs:simpleType>
   </xs:element>
</xs:schema>

I'm sure this can be done with XSLT and I guess it surely doesn't take
much effort to do this. Can anyone give me a little hint on how to
solve this? Thank you!

Best regards,
Chris Marco


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent