Re: A Question **TO** XSLT Newbies
2003-04-24 02:32:57
Andrew Watt wrote:
Hi again Larry,
Greetings! (A bit late in the reply, but I've been busy the past few days.)
We seem to follow each other around on various lists. :)
I'm stalking you.
At 12:24 21/04/2003 -0500, you wrote:
I have to agree on this one. Frankly, I found XSLT itself to be
fairly easy to learn, once I got into it. And thinking declaritively
in general wasn't a problem.
Do you think having worked with declarative animation in SVG helped? Or
have you worked with any other declarative/functional languages?
Actually I was doing XSLT long before I got to SVG. I've been playing
with SVG since last summer, but started with XSLT back in summer 2000.
Some people seem to really choke on the idea of variables that can't be
varied.
Yeah, that left me scratching my head a bit the first time I ran up
against it. Lately I've decided that XSLT's authors must have been ML
fans. (I only just recently looked into ML, too, so I know very little
there aside from the similarities.)
It's figuring out how to pull data out properly that is the problem,
vis, XPath. I HATE XPath. :-) I don't know how universal this is,
but XPath is always the part of any XSLT script that gives me the most
hassle, every single time.
Interesting. Have you any idea why you find it hard? I know that may
seem a stupid question, but have you reached a stage on some aspects of
XPath where a light has gone and you can say "I wish I had
seen/understood that at the beginning"?
If you or others who find XPath hard care to share what it is that you
find hard it would help those of us on list who try to write learning
materials.
Hm. The only time I can think of that came close to that was when
someone (I forget who, unfortunately) posted to this list a link to some
site that discussed using the document() function to have a truely
separate template file that is mostly XHTML, with elements in some temp
namespace used to call to the source tree. It struck me at the time as
Uber-Cool, and I've been using that method ever since. It's a lot more
like the way things seem like they "should" work, since it really
separates format from processing. "Vanilla" XSLT, what I was using
before, makes that separation harder to accomplish.
The "pull" and "push" terminology I picked up from Ken Holman when I was
ushering for him at XML One a few years back in Chicago. (For those
who've not heard Ken speak, I'm sorry. <g> He's one of the best
tech-subject speakers I've ever seen, and practices what he preaches.)
I suppose the 10 cent explaination of push and pull is "pull" is doing
everything via <xsl:value-of /> while "push" is doing everything via
<xsl:apply-templates />. That's a gross over-simplification, and I'm
sure Ken will yell at me for getting it wrong, but the point is that in
push the source tree is in control of ordering and so on, while in pull
the XSLT script's structure controls the ordering and so on. Of course,
any reasonable script mixes and matches both, and that's how you get
neat results out of XSLT.
Most of my work in XSLT/XPath to date has been converting DocBook to
XHTML. DocBook is a very complex, very deep tree, and often I want to
sort or filter or order or group by some element that is very far away
from the current context. For instance, I'm at the context of the book
itself, and want to create a table based on the value of each
<article>'s <articleinfo>'s <keywordset role="SortingStuff">'s <keyword
role="SortThing">, and have the value of "SortThing" be the header for
each table column. I've tried figuring out the XPath for that, and it
just doesn't gel in my head, at least not in a way that ends up giving
me any output. (And that's a simple problem, I'd hate to have to play
with it if I had to go UP the tree.)
I'm actually working on that one right now, so if anyone has any
suggestions on that front I'd certainly appreciate any suggestions. :-)
Another problem I had for a while was fence-post issues. It should be a
simple concept, just using last() and so on, but for some reason it took
me forever to get it to do what I wanted. I don't recall if I ever did. :-)
Another very XPath-specific issue (and another where I would certainly
welcome any help): I have a DocBook tree that looks something vaguely
like this (shorthand):
<book>
<chapter>
<sect1>
<sect1>
<sect1>
<sect2>
<sect2 id="there">
<sect2>
<sect1>
<chapter>
<sect1>
<sect1>Blah <xlink href="#there"> Blah blah.</sect1>
<chapter>
<sect1>
<sect1>
I want the xlink translated into a link to the specified sect2 (or its
XHTML equivalent when it gets generated, which will have an anchor), but
I want the text of the link to be, in this case, "Chapter 1, Section 3,
Subsection 2", dynamically counted. The sections and chapters in this
particular file have a tendency to move around, so maintaining the
numbers by hand really isn't feasible. It seems like a straightforward
problem, but I just can't seem to grok what the XPath for that sort of
"up, back, down, count along the way" statement would be.
I'm not sure exactly what these problems illustrate, but they're the
kind of things I run into often. Notice, none of them is a problem with
the XSLT templates themselves per se. It's with the referencing within
the XSLT from one part of the document to another; vis, the XPath.
Whether that's due to XPath's syntax, questions of context, or both, I
cannot say.
Hopefully that's the kind of thing you were looking for, Andrew. :-)
--
Larry Garfield AIM: LOLG42
larry(_at_)garfieldtech(_dot_)com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an
idea, which an individual may exclusively possess as long as he keeps it
to himself; but the moment it is divulged, it forces itself into the
possession of every one, and the receiver cannot dispossess himself of
it." -- Thomas Jefferson
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
|