Altova Mailing List Archives

RE: [xsl] Generic stylesheet to flatten XML hierarchy

From: "Michael Kay" <mike@--------.--->
To: <xsl-list@-----.------------.--->
Date: 12/5/2009 10:27:00 AM
> But probably you know exactly what you're doing, there is a perfectly
> reasonable algorithm for what you want, and I just haven't
> understood.

I did once write a fairly generic stylesheet for a client that was inspired
by the behaviour of the IDEs that show an XML document in "grid" layout. It
ended up being an interesting set of heuristics that worked quite well for a
reasonable range of input documents (and didn't fail on others). It's best
seen as producing nested tables representing successive levels of hierarchy,
with each table being formatted in one of a number of different styles based
on pattern matching: a "named colummns" style where a sequence of elements
each has N children with different names, a "list" style where elements have
N children with the same name, a "mixed content" style where elements are
displayed as text, and so on. The patterns have to be applied consistently
across the whole document, so for example every order-item element is
displayed in the same way regardless of its own individual structure. 

I can't remember why we decided to drive it from the actual data in instance
documents rather than from the schema, but there was a good reason at the

It was actually a meta-stylesheet, if I remember right: rather than doing
the transformation, it generated the stylesheet to do the transformation.
The idea of that was that once you had the logic to display one purchase
order (say), you would use the same logic to display other purchase orders,
so you got a consistent rendition for all of them; it also allowed
hand-tweaking of the rules.


Michael Kay 

XSL-List info and archive:
To unsubscribe, go to:
or e-mail: <mailto:xsl-list-unsubscribe@l...>


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 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.