[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT Hello World

Subject: XSLT Hello World
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxx>
Date: Mon, 24 Mar 2014 12:05:32 -0400
 XSLT Hello World
Hi,

Over in that other thread, Ihe said:

> Extracting text from an XML document is the hello world of XSLT.
> text() would appear to be an obvious way of doing that and it's really
> important that it entails no surprises. If I were an XSLT antagonist
> that is exactly the sort of thing I would  home in on to portray the
> language as arcane, difficult to use and not suitable for my project.

I find this really quite interesting.

One thing I stress to beginners is that if they're starting to learn
the language using only a syntax reference plus whatever they might
know about Perl, Python or Java, they are heading for a world of hurt.

It's not like your granddaddy's programming language, and when you
assume things like "text() is the way to get my data into the output,
because it says 'text'" ... ouch.

Indeed, the Hello World I like to use looks like this:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</xsl:stylesheet>

I.e., a stylesheet with no templates at all. (You can also write it as
an empty element if you prefer.)

After having acknowledged our astonishment at the results of running
this, we can talk about the built-in templates. And then we start
writing templates of our own ... matching elements, not text nodes. We
do this with a source document with mixed content (such as <doc>Hello
<who>World</who></doc> ), (so we can try a few things out such as
matching elements in line), and then a slightly more elaborate
instance (perhaps including some comments or processing instructions
so we can illustrate aspects of the data model, such as text nodes) .

Take in a few points of fact, practice for an hour or two, and get a
good night's sleep, and you no longer run the risk that you will be
surprised by 'text()' in XSLT.

Talking about the processing model in the context of documents with
mixed content also gives us an early opportunity to start thinking
about XSLT's purposes, strengths and weaknesses.

I know this approach may reinforce the impressions of some programmers
that XSLT is, as Ihe says, "arcane, difficult to use and not suitable
for my project". To this my only answer is in the doing of it.
Assuming your problem is in fact in XSLT's sweet spot, showing how
powerful and easy XSLT is ... once you have a clue ... answers the
critique by itself.

If your problem isn't in XSLT's sweet spot, I ask why are you
interested in it. Yes, XSLT is generally very powerful, and can be
used for problems often quite different from the kinds of document
processing for which it was designed. But please please don't expect
an easy time trying to tackle one of those in XSLT before you have a
feel for templates and traversals.

The thing about "arcane" is also relative. Indeed, if you aren't
naturally a curious sort with a reasonable tolerance for the arcane,
one wonders why you expect to do well with programming at all.

Cheers, Wendell


-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.