A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.
I'm using XML and XSLT to create bespoke messaging formats to different customers.
I plan on having a big block of XML "master" data (per customer message) and a similar, per-message-format "template" XML file and use an XSLT file to massage the "master" XML data into the report format required by the customer.
Customer's sharing the same message format share the same XSLT. Those requiring small changes to output format can have a slightly bespoke XSLT and/or "template."
I am trying to think of the "cleanest" way to join the master data XML (which is dynamically generated from a C# class from a bunch of data sources) to the template XML (read from a file) in order to process both "chunks" by a single XSLT file to produce the final message output.
Can I keep the chunks separate and within the XSLT refer to the "data" chunk and the "template" chunk to build a third chunk (the output) or would I be best just inserting the data XML fragment into the template XML and running the XSLT against the joined XML chunks?
Any advise frm an XSLT "veteran" is much appreciated.
Friday, March 02, 2007
There are basically five different ways to approach this:
1) Use the document() function to load your template XML into XSLT at runtime.
2) Embed the template XML into the XSLT (declare a local namespace, and use the document() function with no arguments, which returns the transform itself).
3) Write a transform that generates the XSLT from the template XML.
4) Embed the template XML into the source XML.
5) Pass the template XML to the XSLT as an argument.
I usually use option 1 if I'm building something small-scale. There's very little difference between the first two options, except that you don't need to worry about using an XmlResolver to get the template document if it's already embedded in the stylesheet. (You don't often need to worry about using an XmlResolver even so.) I tend to prefer the first option simply because during development I prefer tabbing between the XSLT and the XML more to looking back and forth within the same document.
The first 3 options are workable if the template XML is relatively static, i.e. it won't change once you instantiate the XslTransform object. The latter two are more appropriate if different messages require different templates. The last two options necessarily effect performance, because the template XML has to be parsed every time the transform is run.
The third option requires you to be a little more of an XSLT ninja, but in some circumstances you can squeeze a little performance out of a transform by making it a set of static templates.
Hope this helps.
This topic is archived. No further replies will be accepted.Other recent topics
Powered by FogBugz