Re: [xsl] How Can I Reference previous XML in Subsequent Iterations?

Subject: Re: [xsl] How Can I Reference previous XML in Subsequent Iterations?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 18 Apr 2007 17:18:04 +0200
mulberry-xsl@xxxxxxxxxx wrote:
Folks,

First of all, it's great to see some ongoing discussion of XSLT. I've found it very, very difficult to get meaningful help as I come up to speed in XSLT. I have twenty-some years of C++ experience, and ten years of Web design, so I'm not having too much difficulty getting the concepts down.

Hmm, most people have a problem getting rid of there procedural thinking when switching to a more declarative or functional style of a language. The concepts are fundamentally different: in OO/Procedural, the programmer writes down step by step what the computer should do (i.e., the programmer must do a lot of thinking to get the computer do what he wants), and in Declarative programming, the programmer just tells the computer what results he wants, and the computer does all the thinking.


However, the literature and online docs seem to be astoundingly chaotic. I always get dozens of Google hits when I make a query, and very few of them actually answer my question. I've never seen anything like this before.

Well, I feel the same when looking for something in the C++ world (biggest problem: the '++' in the word), where I usually get too much information. But after a while, you'll feel more comfortable and you'll start using the right queries. I often use Google with "XSLT faq" and then the keywords. The answers are mostly in the first few hits.


About the literature: I found the XSLT Cookbook and the XSLT Programmers Reference very valuable.

Here's the question:

I'm starting a pretty ambitious XSLT project. I'm transforming Microsoft Excel XML files into inline XHTML for display on a wiki.

If anyone has seen the Excel schemas, they know that this is not a project for the faint of heart.

There has been more discussion about XSLT + Excel on this list. You may want to check the archives.


This means that, as I iterate through an XML file,

You don't iterate though the XML file (not with XSLT that is). The processor does that for you. You only declare what the outcome should look like.


I need to yank out a @Style attribute, fetch a previous style declaration, and shoehorn that declaration into the current element's style attribute.

Well, that looks like you have some globally accessible element and you need its value when your context is around some deeper child. Seems to me something you could 'shoehorn' with xsl:key, or a simple /path/to/style lookup.


So, why do I need an expert opinion?

It seems, from my previous research, that there is no way for XSLT to store persistent information.

You don't need to. You persist the results to disk or elsewhere. That's all.


"Variables" are about as close as it comes, and I might be able to do it with them, but they are very, very stiff, primitive and awkward.

Hmm. When I first started out with XSLT my first question was similar: how can I assign to a variable? Etc. But what XSLT calls variables has *very little* to do with what you call a variable in a C++ or similar procedural language. And they are a magnitude more powerful.


In any case, I may not have a choice,

Plenty of choices around ;)


I am using php:functionString callouts,

You should not be needing them for the problem you describe.


Any ideas?

Plenty, but we need a little more info. Can you provide us with a smallest-possible example that illustrates your problem? Provide input XML and your expected output XML and how they relate to one another (please subscribe to the list, instead of digest while in the discussion)


Cheers,
-- Abel Braaksma

Current Thread