Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

What's Your Mental Image of XSLT?

by Cody Pendant (Prior)
on Oct 10, 2003 at 22:58 UTC ( [id://298440]=perlmeditation: print w/replies, xml ) Need Help??

I'm getting to grips with XSLT at the moment, and not loving the O'Reilly book, I'd have to say.

But I realised this morning that one problem is that I don't really have a little picture in my head of what XSLT does.

XSL Transformations, as everyone is careful to tell you, are very much not procedural, but they're not really like OO programming as far as I can see, although it's all about objects. You aren't even guaranteed that your elements come out in document order, right?

So, I have a mental picture of what happens when perl does

while(<FH>)
which is like the file being fed through a machine, say a grinder, and I have a mental picture of how regexes work, which involves a team of ants crawling along strings (some of them stay behind to mark the places when alternation is involved) and so on.

Objects, I've decided, get fed their methods, bulge a little, then spit something out. All you get to see is the mouth.

But I don't have a mental model of an XSLT transformation.

Has anyone else? It's all about Trees, so do you see a monkey climbing the tree and picking the elements off as fruit?

I know I can't be the only one who needs a visual, no matter how strange, in order to think through these kinds of things

... can I?

<crickets heard in distance>



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: What's Your Mental Image of XSLT?
by simon.proctor (Vicar) on Oct 10, 2003 at 23:25 UTC
    I tend to think of XSLT as tree walking but with a twist. I find that model keeps me sane for the simpler templates.

    Each template is really made of smaller templates, which in turn can be made of smaller (etc). In my mental model I match my tree walking to my templates, so for large general sections of the tree I have larger, general templates (if you see what I mean).

    So I guess I map fragments to fragments like two bits of velcro or two bits of a sandwich (or something).

    I find that where it begins to get hard is when you start to do node processing using XPath. Really XSLT and XPath go hand in hand and its hard to get anything complicated out of XSLT without having a good grounding in XPath.

    However, this is where I think XSLT can fall down, I have had to write some very complex XPath queries that I know most of the content developers wouldn't have a hope of producing - hence, at work, I'm one of the only people to use it.

    I got the O'Reilly stuff too and I don't think they are much good (but thats my PERSONAL opinion ;) ). I'd search the web for XPath tutorials and play with a self generated XML document for an afternoon.

    Just my 2p :)
Re: What's Your Mental Image of XSLT?
by BrowserUk (Patriarch) on Oct 11, 2003 at 01:02 UTC

    My first thought

    For a mental image of XSLT, the first thing that sprang to mind when reading your post was the council chamber at the European Union, or the debating halls at United Nations.

    If you've ever seen news footage of those places when a well supported debate is in full flow and seen the army of translators running around whispering on-the-fly translations into the ears of the delegates, observed the confusion on those delegates faces as they get miss-predicted or misinterpreted native language translation of the current speakers words, followed (hopefully) by the dawning of realisation as the translations are corrected in real-time. Seen their initial reactions of confusion or disgust turn to realisations of understanding and joy -- or vice versa -- then you may understand my mental picture.

    I've seen various attempts at defining a common language for computer systems intercommunication that have been forthcoming over the years. Unfortunately, like Esperanto, nobody ever quite talks them the same way. Each native (proprietary!) speaker has the habit of imposing their own native dialect upon the basic structure and semantics of the language. Each tries to use and extend the use of the "common language" to incorporate and reflect the semantic variety, expressiveness and beauty of their own native language. The result is that they end up speaking as many dialects of the common language as there are native languages -- and often more, as each individual 'native-X' speaker tends to enhance their vocabulary in different ways.

    A second view

    For a second mental image, I go back to an unscheduled stop-over I made in New Delhi, India a few years ago. I was on a flight from Hong Kong back to the UK that was meant to touch down at New Delhi, re-fuel, exchange a few passengers and fly on. Four of the 16 main tyres on the jumbo jet burst upon landing and they didn't have replacements to hand, so we ended up being forced to spend the night and the following day in local hotels whilst replacements where flown in.

    In most ways, this was a delightful and pleasurable experience as the hotels were superb, the cuisine excellent and the local people as interesting and friendly as they were diverse. There was one fly-in-the ointment. None of we transit passengers had the requisite visas for entry to the sub-continent, and so, for security reasons, our passports were taken from us at the airport prior to being bussed to our hotels. Theoretically, this meant we were confined to our hotels for the duration, but most of us found that a few English pounds or US dollars would hire us a taxi for the day, and we went out in small groups and got to see some of the local sites, markets and so forth. Great fun. The problem arose when we returned to the airport the following evening.

    We were assembled in a large room in order to have our passports returned and to go through the customs and 'emigration' procedures. A very pleasant Indian Customs official, complete with a uniform that wouldn't have looked out of place on the Captain of the Titanic turned up after about an hour (a short delay by sub-continental standards:), and announced that he had our passports. Three, somewhat less resplendently dressed sub-officals came in with 4 large black bin bags containing the 300+ (from 20+ countries) passports. These were placed upon a large trestle table erected for the purpose and the official proceeded to reach into the first bag, remove a passport, open the cover and read out the name of the owner who was to move forward, be identified and retrieve their passport.

    The problem was that with the nice officials fairly strong subcontinental accent, names (often phonetic translations) from 20 odd countries ranging from China, Malaysia, Australia & New Zealand through Abu Dhabi, Bahrain and Egypt, to Sweden, France, Greece, Spain and the UK, the pronunciations left something to be desired. Hearing and interpreting your own name when spoken by a non-your-language speaker is itself quite difficult, but when your surrounded by 300 other non-native speakers all questioning each other as to whether that last, staccato collection of consonants intermingled with sing-song vowel sounds was their name or not, it became incredibly confusing and difficult. It got worse -- much worse -- and the flight eventually took off some 5-hours later, but the rest of the story doesn't have relevance :)

    I guess my point is that I've seen various attempts at providing a common, platform-independant mechanism for communications between systems, and so far none of them really live up to the hype. I fully understand the need for such an animal and support the aims, but the implementations leave so much to be desired. The problem is that you either end up with the lowest common denominator which results in complex and sophisticated systems talking to each other in terms of simplistic, verb-adverb-adjective sentences, which is a bit like a Russian and Chinese nuclear scientists communicating to each other via English baby-talk. Or you get a intermediate communications protocol that is so complex, as to allow the most sophisticated ideas and concepts from any proprietary system to be communicated to any other. A fully-defined, orthogonal and extensible protocol -- like XSLT.

    The result is that every communicator has to implement detection and recovery procedures for every conceivable language construction, even if it will never use those constructions itself, or would be capable of processing them if it received them. That often leads to the situation where it becomes policy for companies and organisations to adopt such protocols "for all inter-systems communications", even when those systems are their own, similar, never-will-talk-to-the-outside-world, systems. This imposes a huge burden on both the development and runtime for these systems and can lead to dumbing down or castration of individual systems design, because the need to be able to translate all internal data structures and concepts into the intermediate protocol prevents unique and complex (but fitting) structures and concepts being used.

    A final image

    For a final image, imagine a brain surgeon trying to perform his trade using 30 foot long poles to prod the lower-lumbar regions of proxy-surgeons that enter commands on keyboards that control industrial robots that actually perform the brain surgery.

    Trying to perform many of the types of transformations required by inter-systems communication -- date-format; numeric-format; case, codepage and language conversions etc. bits and bytes stuff that most computer systems handle easily and efficiently -- using a "program" written in XML, seems somewhat analogous :)

    As you might have gathered, I'm not particularly impressed by XSLT. I see the need for it in some particular circumstances, but in 90% of cases, there is no need to divorce the logic from the underlying systems quite so completely. Most concepts in computers are transferable between individual systems without resorting to a protocol that is so far removed from the underlying mechanisms. For the 10% that do require such machinations, there has to be a better way. I don't know it yet, but I'm pretty sure it will be along some time soon :)

    My conclusion is that you shouldn't resort to such mechanisms unless you have a real need to, and if you have, I commiserate with you.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

      Having now written a fair bit of XSLT, all I can say is that this is such a grandiosely melodramatic image as to be ridiculous. It’s as if someone was composing an intricately elaborate image of how writing Perl was like herding cats that chase mice running over wires in order to produce just the right line noise to get a working program – or some such absurd preconceived notion.

      The problem is, I’ve never seen introductory material that manages to do proper justice to the language in its unmatched expressiveness and conciseness when manipulating XML documents. Most people get blinded by the superficial verbosity of the syntax as expressed in XML – which I hate as much as anyone –, and never realise the beauty and elegance of the semantics that the syntax expresses.

      Makeshifts last the longest.

        ... its unmatched expressiveness and conciseness when manipulating XML documents.

        You obviously haven't tried doing anything other than very simple translations and substitutions. Try doing something that expands one element into a number of element groups; or collating a large number of groups in order to produce summary statistics; and see any elegance (which I never perceived), and any pretence at conciseness disappear.

        But mostly you are missing that an XML document is never the final form required by an application. Try loading a wordprocessor document from it's native (binary) format, and the same document from an XML representation and see how much extra time/cpu is used by the later. Same thing for spreadsheet data, and rdbms data, etc.

        Try performing SQL type outer, inner or cross joins on tabular data held in XML format using XSLT. Then tell me that it is elegant and concise.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: What's Your Mental Image of XSLT?
by Zaxo (Archbishop) on Oct 10, 2003 at 23:26 UTC

    If you want to stick with a tree analogy, you could think of XSLT as mechanism for whitewashing the trunk, tying on yellow ribbons, hanging Christmas lights, gathering nuts, and sawing it up for lumber - all in the chosen season.

    More prosaicly, I think of it as a stylesheet mechanism. It provides a generalized "stringification" for the presentation of XML elements.

    After Compline,
    Zaxo

Re: What's Your Mental Image of XSLT?
by dws (Chancellor) on Oct 11, 2003 at 08:14 UTC
    It's all about Trees, so do you see a monkey climbing the tree and picking the elements off as fruit?

    I could kind of grok XPath without resorting to visualization, but had to visualize trees to cope with XSLT. And for reasons probably anchored in exposure to antique CS texts, I visualize trees upside down (i.e., root at the top). So in this case the monkeys would be rearranging the tree while hanging on for dear life.

    Someone, and I wish I'd saved the link, has a visual explanation of XSLT that draws trees from the top down, and color-codes the tree parts targeted and affected by various XPath/XSLT fragments. Just looking at things organized this way was enough to part the clouds enough to give me a grip on the big picture.

Re: What's Your Mental Image of XSLT?
by pg (Canon) on Oct 11, 2003 at 04:18 UTC
    XSLT is methodology to describe how different sets of entities and properties could be linked together, which futher extends our ability to clearly seperate entities and properties that shall be handled in a modulized approach, as we now have a powerful tool and have more confidence that we are able to describe and deal with the linkage easily with XSLT.
      Some interesting responses there, for which I thank you.

      I'm not sure I quite understand yours, pg. It's the kind of abstract stuff that makes my head hurt.

      Does anyone have a mental mapping that they use with Perl/SQL code, (he said, widening the discussion a little)?

      Do you for instance think of

      <xsl:apply-templates select="item">
      as
      SELECT * FROM xml_document WHERE element_name = 'item'
      and
      <xsl:template match="item"> <p> <xsl:value-of select="." /> </p> </xsl:template>
      as
      while(fetchrow-hashref){ print '<p>' . $value . '<p>'; }
      that kind of thing?


      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

        Interesting... you know what, I actually had the same thought to compare XML with database and XSLT with SQL...

        Actually there was (is) a XML query language defined, although I don't think it gained any serious attention.

        More than SQL, which is just a set of command to manipulate the data in storage, XSLT is actully more similar to PL/SQL in terms of role.

        To be quite frank, comparing with database, i am not in favor of XML at all, and have the feeling that XML will go away after a while (of course everything goes away eventually, but XML is not a very big success, in terms of technology).

        Although XML is something new, but I can see lots of stuffs in it simply goes backwards.

        Performance and bandwidth are two biggest problems with XML, and I strongly believe they are XML built-in. (Well one can always call something XML, even after it being foundamentaly modified *enhanced*, but to me that does not count)

        What's your thought?

Re: What's Your Mental Image of XSLT?
by xaphod (Monk) on Oct 11, 2003 at 15:56 UTC

    XSLT...

    It's like baking a cake when you have empty cupboards and you have to run to the shops to buy each ingredient when the recipe calls for it.

    So flexible that you can bake anything in the recipe book... But not exactly the most efficient way to do things.

    --
    TTFN, FNORD

    xaphod
Re: What's Your Mental Image of XSLT?
by sfink (Deacon) on Oct 11, 2003 at 17:54 UTC
    Just imagine a little ways into the future, when even more of the tasks currently done by humans are done by robots. Further imagine that the transition is done by companies desperately cutting costs anywhere possible, and therefore not thinking too hard about the possible safety implications of some of these machine-for-human substitutions.

    So for example, you go to a plastic surgeon and show him several pairs of pictures. Each pair contains a photo of some feature on your body, and a photo of the same feature on someone else's body the way you want to look.

    Unfortunately, the system isn't set up very well, and your photos get a little mixed up.

    You feed those photos to a computer, lie down on the operating table, and pass out. A robot scans your entire body looking for things that look like any of the "before" pictures. When looking for your nose, it finds your nose, a small lump in your hair that coincidentally happened to resemble a nose, and your left elbow. It analyzes each one to figure out what part is the right nostril, what is nose hair, etc. It then proceeds to make each of those three places look as much like an ear as possible (that being the picture that got mixed up with your nose picture). However, it doesn't just carve an ear out of your elbow; it believes that it knows what part of your elbow was the bone in your nose and leaves it untouched, while ripping and tearing and rearranging other portions of your elbow so that they would look ear-like had they been the appropriate parts of a nose to begin with. As an end result, you end up with slightly messed up hair, an ear where your nose used to be, and a pulpy, bleeding mass of shredded tissue and splintered bone where your left elbow was.

      ewwwww!

      -theo-
      (so many nodes and so little time ... )
      Note: All opinions are untested, unless otherwise stated

Re: What's Your Mental Image of XSLT?
by Willard B. Trophy (Hermit) on Oct 11, 2003 at 19:48 UTC
    XSLT, from me, is like awk for structured data. It finds a match, does its thing, and starts all over again. That's all I've ever needed to know about it.

    Lurk awhile on the Mulberry Technologies XSL-List, and all will be clear.

    XSLT may not currently be the fastest tool, but it works the way I think. But I always was a weird kid.

    --
    bowling trophy thieves, die!

Re: What's Your Mental Image of XSLT?
by Anonymous Monk on Oct 11, 2003 at 16:18 UTC

    I visualize XSLT as a nude woman.

    ... come to think of it, I visualize everything as a nude woman.

    Anonymously yours,
    Anonymous Monk

Re: What's Your Mental Image of XSLT?
by Cody Pendant (Prior) on Oct 11, 2003 at 22:13 UTC

    Thanks again, everyone for taking part. I'm getting a faint, distant hint of an inkling that not everyone likes XSLT or even XML...

    The reason I'm having to get to grips with it is that there are voices lobbying for XSLT to be used as the transformation language for the new Content Management System where I work.

    It would of course be better than making up Yet Another Templating Language ourselves, but in most other ways I'm distinctly unhappy about it...



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
      I'm getting a faint, distant hint of an inkling that not everyone likes XSLT or even XML...

      XML is a fairly decent platform neutral way to express hierarchical data. XSLT is a decent way to express--again in a platform neutral way--transformations on hierarchical data. Performance is an open issue.

      Martin Fowler has another take on XSLT. See http://www.martinfowler.com/bliki/MovingAwayFromXslt.html.

        The really great thing about XSLT is that at least it's not DSSSL. DSSSL is basically Scheme with embedded CSS-like constructs. It, unlike the bagpipes, smells as bad as it sounds.

        The really, really great thing about XML+XSLT is that you can just blat them at the client's browser and, for sufficiently correct values of "browser", you get rendered content. Transformation too slow? Get a proper computer, pal, it ain't our servers.

        All markup and associate transformation languages suck; they, by definition, have to. After all, in order to fit your abitrary data into a structure that anyone else can understand, you've got to pack in a wheen of redundancy, convention and plain old hope to make sure the message gets through.

        --
        bowling trophy thieves, die!

Re: What's Your Mental Image of XSLT?
by DrHyde (Prior) on Oct 11, 2003 at 17:55 UTC
    My mental image of XSLT is of a great steaming pile of second-hand dog. Consequently, I avoid it and try not to mention it in polite society.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://298440]
Approved by dws
Front-paged by dws
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-24 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found