[Home] [By Thread] [By Date] [Recent Entries]
At 2011-09-04 09:59 +0000, Alex Muir wrote:
Something I'm just wondering for the sake of learning more...
Would XSLT... You mean like XQuery? I'll cite again the ability to tweak the behaviour of a read-only stylesheet. There is the scenario I mentioned earlier of creating the "editor's rendition" stylesheet by exploiting the "user's rendition" stylesheet with overriding behaviours. Also, imagine it is the 11th hour of a project, a stylesheet has been through some kind of quality assurance, and the boss comes up with a last-minute change. The well-defined semantics of <xsl:import> means that the onion-skin overriding stylesheet can redefine global declarations used by the imported stylesheet, and do so without creating declaration collisions. The new combined system works as desired and you haven't touched the base stylesheets that have already gone through tests. As careful as we all are when we make changes to existing stylesheets, using <xsl:import> you can, hand on heart, claim you didn't touch the base read-only stylesheets and you've implemented all of the changes you need through the onion skin. You can't do this in XQuery because the global declarations clash. You can't do this in XQuery because "global" declarations are only global to the module and the including modules, but not to any other modules. You can't do this in XQuery because it is imperative and not declarative. 2. Be much more difficult to program certain things or perhaps just less convenient?
Declarative solutions come up with the same results as imperative solutions, but you have far more flexibility adapting and leveraging a declarative solution than you do an imperative solution. If programs never needed maintenance, then this discussion would be less important. Though the powerful XSLT features are not only exploited when maintaining a stylesheet ... they are also very useful when developing a stylesheet. 3 Be something else....
Without it, stylesheet writers would have to think more imperatively about their stylesheet fragments and have to "program around" the competing declaration issues, rather than let the specification arbitrate between competing declarations in a well-defined fashion. Sadly, programmers with imperative programming styles (that includes XQuery writers) who approach XSLT either don't understand the declarative benefits of using <xsl:import> or simply don't bother looking because they are stuck thinking in an imperative fashion rather than a declarative fashion. I wonder if confusion arises from the words include and import not really conveying much logical difference in functionality given that no doubt studying these terms is a good idea before using them as I did with MK's book.
Encountering lower-precedence imported constructs before higher-precedence constructs in the importing fragment is likely helpful to the implementer (I don't know, I've never implemented an XSLT processor). Distinguishing different semantics with different names can be, I believe, better than overloading dramatically different semantics on constructs with the same name in the presence of optional attributes. Though, of course, a balance has to be struck regarding "dramatically different semantics" or we wouldn't have any optional attributes on any elements. I think it is unfair to criticize in hindsight the choices made by designers of the language. There was plenty of time at the time for the choices to be debated, and many talented people participated at that time to come up with meaningful choices. It seems too easy to say now "they did it wrong" when in fact what they did has been very successful. XSLT is a very powerful language that can be used very powerfully and very simply when used correctly. I also see a lot of hindsight criticizing XML namespaces unfairly. The time to have debated it was the time it was being designed, not after the fact. I would rather code be more specific and write a bit more code than there be rules like the ordering of the xsl:import giving different precedence. I find that is thinking imperatively and not declaratively. I think it better the code specify the import precedence with english given that would take only a little bit of code for the extra clarity and we wouldn't be having this discussion I assume.
This feature strikes a good balance between helping the implementer (requiring the import constructs to be first in the stylesheet) with helping the stylesheet writer (clear semantics on the difference between import and include). I suppose generally the things I don't like about xslt are the things that happen as your learning that language but are not "clear" why like when you get xmlns="" or some other namespace output on your elements for the first time and your just thinking to yourself I don't want that to happen. I didn't ask for that to happen.
It's really not clear to a new user and a bit annoying in my view. (hmmm sorry for the "clarity" tangent but that is my one and only beef with xslt so it came out... I just wish xslt output what I wrote exactly.
It seems much easier and more clear to add a namespace on my own than take it away. I suppose this should be in a different post..) Indeed it might be better in a different post. <soapbox> I approached XSLT (and before that DSSSL in 1996) with the perspective of an imperative programmer (I'm a second generation programmer as it was my father's trade and I started programming in imperative FORTRAN (FORmula TRANslator) 40 years ago in June 1971). I made all of the mistakes in XSLT that other imperative programmers make. I recognize these mistakes in the classroom when the students make them and I can show them the light provided by XSLT. The specification was designed by brilliant people who have given us tremendous power. Without that power, if XSLT was designed only for "the simple first-time attempts", then there would have been no reason to move to XSLT from other languages. But because XSLT is designed the way it is, and doesn't cater to only "simple first-time attempts at transformation", it is far better suited than all other languages for certain classes of problems to be solved. Remember that XSLT was initially written as chapter 2 of the XSL (XSL-FO) specification. It was only taken out of the XSL specification when its amazing design principles were seen to be useful in other transformation scenarios. In publishing scenarios, the declarative nature of XSLT is ideal and I've made a very successful living out of implementing customer solutions in this area. And I've been able to exploit the powerful declarative nature in non-publishing solutions as well because the language features allow me to do so in XSLT much more easily than other languages. Heck, I never understood APL but users of APL found it a tremendous language for the class of problems APL was designed for (matrix manipulation if I understand correctly). It too was declarative. I don't think APL programmers would want to have to implement their solutions imperatively. If my customers came to me with problems requiring matrix manipulation, then I'd take the time to (try to) learn APL and solve their problems and get paid. Thankfully, they don't! Horses for courses. There is no |ber-programming language. There is no |ber-programming style. I'm glad XSLT was not hobbled to be like other programming languages. XSLT should not be derided for not acting like other programming languages. </soapbox> I hope this helps. . . . . . . . . . . . . . Ken
|

Cart



