XML meets SQL
Sometimes the bodges are mandated by the client.
Client ran a digital print service. They got flat files, usually CSV to print. The printers were driven by a package which took in flat files with one line per field in the document together with a formatting in file which told where & how the field was printed. The normal work-flow was to store the contents of the incoming files in a relational database & then pull the data out in the field-per-line format. Having the stuff in the database helped manage batching, remakes etc & also made the conversion from one flat file format to another fairly transparent. The normal IT work-flow had been to write a system for this more or less from scratch for every contract. I'll draw a veil over the contract where the data came via EDI...
Along came a contract which needed this new-fangled XML stuff. The document was way more complex than the usual stuff and flat files wouldn't have handled it. I put myself up to handle the XML end & did some training on the subject. The obvious route was take the original XML & apply XSLT to convert it into the field-per-line format. To handle the usual work-flow requirements the incoming XML could be split into fragments, one per printed document, stored as text elements in the database and reassembled for a batch job. Client said 'No'.
They wanted the XML taken apart and stored in relational form just like all the others except this time it would require a whole hierarchy of tables and it quickly became clear that for performance reasons surrogate keys would have to be used to tie stuff together. I ended up with XSL to convert the XML to SQL with a series of macros to act as place-holders for the keys and a macro-processor to handle the tying together. Inevitably more sections were added to the document format and hence to the XML over the life of the contract. The database design was tied to the document structure and chunks of the code were tied to the schema so the client had committed themselves to changing both at intervals through the life of the contract.