[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Generic stylesheet to flatten XML hierarchy


Subject: RE: [xsl] Generic stylesheet to flatten XML hierarchy
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 5 Dec 2009 10:26:42 -0000

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

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.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


Current Thread
Keywords