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

Subject: Re: [xsl] How Can I Reference previous XML in Subsequent Iterations?
From: "Chris M." <chris@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 18 Apr 2007 11:30:05 -0400
Thanks, this should get the thread going with the correct address.

I appreciate the thorough and well-thought-out answer. My comments inline:

On Apr 18, 2007, at 11:18 AM, Abel Braaksma wrote:

* Replies will be sent through Spamex to abel.online@xxxxxxxxx
* For additional info click -> http://www.spamex.com/i/?v=14869346

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.



Yeah, see my previous comment. I think my metaphor of a "control panel" is fairly accurate. The main issues I have with the way XSLT works is with the way states change all the time. For example, if I want to compare a value to the value of the previous iteration in an xsl:for-each loop, I need to first extract the value and store it in a "variable," as the XPath state changes, and you can't reference it easily in the predicate, which has a state defined by the node being tested at the time.


That was Excedrin Headche #1, but I figured it out.

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.

Thanks! I'll follow up on this.



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.

I'll check it out.



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.

That's the $64,000 question. How do I do that?



"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


Chris Marshall
chris at getridofthiswholelongthingybecauseitstoconfusescrapers littlegreenviper dot com
http://www.cmarshall.net/


Current Thread