|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: seriously trivial question about processing the ro
At 2003-03-19 17:16 -0500, Robert P. J. Day wrote:
more than one book i've been reading has presented examples of processing an XML document whose document element is, say, <doc>, with: Absolutely yes there is value. at least in the above example, it seems to be little more than aesthetics. is this accurate? Not at all from my perspective ... I believe much more than aesthetics are involved. Actually, I counsel the students of my training courses to do the above because it "protects" a stylesheet from abuse. From XSLT's perspective, *every* stylesheet will work with *every* source file ... where "work" is loosely defined as "produce a well-formed result from the given inputs". Consider that I have a business card stylesheet that skips over the document element <card> and just relies on the built-in templates to get to the template rules for <name> and <address>. Should I accidentally or maliciously pass an invoice instance to the business card stylesheet, the built-in template rules might easily find <name> and <address> under <buyer> and nicely format my invoice instance as a business card ... accurate but nonsensical results. However, with a root template rule that pushes the <card> child, a passed <invoice> instance will produce an empty result: this is not a well-formed instance (though it happens to be a well-formed external parsed general entity) and would appropriately choke the next step of a multi-step transformation as a document entity, or at least would easily be recognized as the result of improper use of the stylesheet. So far, so good ... but what if I pass a greeting card instance with a <card> document element to the stylesheet? That would also produce nonsensical results. At this point I support my argument to my students that "namespaces are good, not evil" and show the students how: <xsl:stylesheet xmlns:bc="http://www.....com/ns/businessCard" <xsl:template match="/">
<xsl:apply-templates select="bc:card"/> <xsl:template match="bc:card">
...Would be the *best* protection from a business card stylesheet being abused by being passed an unexpected source document that might kick in the built-in rules to produce a non-empty but nonsensical result. So I personally consider such a practice as a "good" practice. And it supports my namespace preaching. It is not at all a trivial practice from my perspective. I hope this helps. .................... Ken
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








