Subject: Re: [xsl] XSLT use cases; data-centric to document-centric transformations|
From: Peter Gerstbach <peter@xxxxxxxxxxxx>
Date: Mon, 07 Feb 2005 19:39:50 +0100
- Does anybody agree/disagree to my classification?
Oh, I expect so:-)
It isn't always clear whether a particular XML file is data or document centric for a start. In particular many basically "document" oriented formats that support mixed data have "data centric" subsections (eg lists of bibligraphies or metadata sections) I think XSLt was intentionally designed to handle both these cases.
but the programming style is more imperative (for-each) than template based (apply-template).
I know what you mean here but the distinction between imperative and declarative programming styles doesn't really coincide with using or not using apply-templates. xsl:for-each is (always) equivalent to using apply-templates with a unique mode, and a single template in that mode, so for-each is just a syntactic shorthand for one restricted usage of apply-templates, not a completely different paradigm that one can make hard and fast rules about.
- How can I handle use case 3)? To my mind it would be best to convert a data-centric XML into a well structured documen-centric XML and then apply a XSLT stylesheet.
I don't understand this question. Or at least, I don't understand the proposed answer. How would you do the conversion that you mention? If you use XSLT then you would presumably need a stylesheet of your type 3, so this solution appears to be circular?
<orderedProducts> <product> <name>product A</name> <price>120</price> <quantity>2</quantity> </product> <product> <name>product B</name> <price>90</price> <quantity>1</quantity> </product> </orderedProducts>
<document> <header>the logo, the company name</header> <body> <p>Some text what this is about</p> <table>...</table> <!-- here comes the table with the products --> <p>And maybe some text again.</p> </body> </document>