I am working on something where data is delivered in various XML formats, and although I can figure out most of the pieces of how to parse it, I do not know enough about XSLT and XPath to know where to begin putting together this type of multiple transform, where some data is obviously just looked up, some data is repeating, elements have to be renamed, some data is in attributes and some in values, and templates probably have to be processed in specific order or be called with variables. I don't think there is this type example present here, and if we could get one, it might solve a lot of issues for people.
The goal is to take input from several sources which provide similar data in different forms, translate them to a common XML form, and write only ONE (1) progam processing path, instead of the four (4) that we now have to maintain. Also, the translation should be easy to deserialize.
Any way, here is a fair example of an INPUT file:
<?xml version="1.0" encoding="utf-8"?>
<PackageName TransmissionID="0792d49a-c09b-4094-9f4e-2357a042865c">
<Version>1.0</Version>
<DateReported>04/12/2010</DateReported>
<TimeReported>10:16:46.9385105</TimeReported>
<!-- Status=Disposition -->
<ReportPackage Status="Disposition1">
<Addresses>
<Address>
<!-- PersonAddress -->
<Name>Stephen Stipulate</Name>
<Address>1200 Any Street</Address>
<City>Some City</City>
<State>XX</State>
<Zip>12345</Zip>
<Phone>800-555-1212</Phone>
</Address>
</Addresses>
<Parts packageID="APackageId">
<packageClientAccount>00000000</packageClientAccount>
<DiscardedIdentifier id="NothingOfInterest">
<AssemblyId>
<IdValue>0547224801-0908</IdValue>
</AssemblyId>
<!-- Status -->
<AssemblyStatus>
<Status>OutOfStock</Status>
<DateReOrderReceived>2009-09-24T06:09:00</DateReOrderReceived>
</AssemblyStatus>
<PartVendor>
<!-- VendorAddress -->
<VendorName>Roger Refactor</VendorName>
<VendorAddress>
<IdValue name="Address">100 An Avenue Suite 13</IdValue>
<IdValue name="City">A Different City</IdValue>
<IdValue name="State">YY</IdValue>
<IdValue name="Zip">54321</IdValue>
<IdValue name="Phone">866-555-1212</IdValue>
</VendorAddress>
</PartVendor>
<PartsMainSegment>
<AdditionalSegment>
<PartSpecs>
<Spec>
<PartId>123456</PartId>
<Name>Widget1</Name>
<ThresholdLevel>000500</ThresholdLevel>
</Spec>
<Spec>
<PartId>234567</PartId>
<Name>Widget2</Name>
<ThresholdLevel>000200</ThresholdLevel>
</Spec>
</PartSpecs>
</AdditionalSegment>
</PartsMainSegment>
<AdditionallPartsSegment>
<Spec>
<PartId>123456</PartId>
<PartType>ABC</PartType>
</Spec>
<Spec>
<PartId>234567</PartId>
<PartType>CBA</PartType>
</Spec>
</AdditionallPartsSegment>
<AdditionalItems type="RawData" qualifier="mode" vendor="rogerRefactor">
<Text>AModeValue</Text>
</AdditionalItems>
<AdditionalItems type="RawData" qualifier="indicator" vendor="rogerRefactor">
<Text>AnIndicator</Text>
</AdditionalItems>
</DiscardedIdentifier>
</Parts>
</ReportPackage>
</PackageName>
And the desired OUTPUT file:
<?xml version="1.0" encoding="utf-8"?>
<Package>
<TransmissionID>0792d49a-c09b-4094-9f4e-2357a042865c</TransmissionID>
<PackageType>PackageName</PackageType>
<Version>1.0</Version>
<DateReported>1/03/2011</DateReported>
<TimeReported>16:25:35.1293170</TimeReported>
<Disposition>Disposition1</Disposition>>
<packageID>APackageId</packageID>
<packageClientAccount>00000000</packageClientAccount>
<Addresses>
<PersonAddress>
<Name>Stephen Stipulate</Name>
<Address>1200 Any Street</Address>
<City>Some City</City>
<State>XX</State>
<Zip>12345</Zip>
<Phone>800-555-1212</Phone>
</PersonAddress>
<VendorAddress>
<Name>Roger Refactor</Name>
<Address>100 An Avenue Suite 13</Address>
<City>A Different City</City>
<State>YY</State>
<Zip>54321</Zip>
<Phone>866-555-1212</Phone>
</VendorAddress>
</Addresses>
<Parts>
<AssemblyId id="0547224801-0908">
<Status>OutOfStock</Status>
<DateReOrderReceived>2009-09-24T06:09:00</DateReOrderReceived>
<Part>
<PartId>123456</PartId>
<PartName>Widget1</PartName>
<Level>000500</Level>
<PartType>ABC</PartType>
</Part>
<Part>
<PartId>234567</PartId>
<PartNameName>Widget2</PartNameName>
<Level>000200</Level>
<PartType>CBA</PartType>
</Part>
</AssemblyId>
</Parts>
<AdditionalData>
<Vendor>TheVendor</Vendor>
<Mode>AModeValue</Mode>
<Indicator>AnIndicator</Indicator>
</AdditionalData>
</Package>
We actually get XML similar to this reporting to a web service. Notice the required re-names, movement of data to different parts of the tree, and also in particular the different segments which have to be joined to make a list of part records, which do not have a parent/child relation. I am not offering any bad starting attempt, as I am at a loss as to where to start on this since I simply don't understand how to sequence the processing, and I am certain that somebody out there (Dimitre!), while not on purpose, would make me look like an idiot! :)
Well thanks for any and all help - cheers! :)