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

Subject: RE: [xsl] How Can I Reference previous XML in Subsequent Iterations?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 19 Apr 2007 09:54:41 +0100
Yes, handling Excel input is a pig. One thing that can make it easier is to
do a transformation pipeline: first do transformations that make the Excel
XML more tractable, then do further transformations that deliver the output
you actually want. One advantage of this approach is that the initial
transformations will be reusable next time you want to convert Excel to
something different.

The basic answer to you problem of finding the style information is to
structure your code according to the output you want to produce, not
according to the input document. When you want to produce something in the
output, do the navigation that finds the information from wherever it
happens to be in the input. Often that can be done with a single XPath
expression; but with Excel style information it involves following an
arbitrarily long sequence of key references, so this needs a recursive
function or template. This kind of thing is easier using functions in XSLT
2.0, but you can do it using named templates in 1.0 if you really have to.
If the navigation gets too complex or repetitive, then think about adding a
preprocessing phase into the pipeline that converts it into more accessible
form.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: mulberry-xsl@xxxxxxxxxx [mailto:mulberry-xsl@xxxxxxxxxx] 
> Sent: 18 April 2007 15:45
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] How Can I Reference previous XML in Subsequent 
> Iterations?
> 
> 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.
> 
> 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.
> 
> Someone suggested that I post a question I asked in another 
> forum here. The question is collecting dust on the other 
> forum, but I hope that I can get an answer here.
> 
> 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.
> 
> In any case, a pretty universal Microsoft schema structure is 
> to have a whole bunch of styles up front, and then reference 
> those styles in attributes throughout the document.
> 
> The way that most people would render this would be to stick 
> the styles into the <head>, and reference them through class 
> attributes in the body.
> 
> Simple, no?
> 
> No.
> 
> As I mentioned, I'm transforming these **inline**, so that 
> means that I need to make the styles actual "style" 
> attributes, not class references. I may have three different 
> spreadsheets on one Wiki page; each, with its own view of how 
> a number should be formatted.
> 
> This means that, as I iterate through an XML file, I need to 
> yank out a @Style attribute, fetch a previous style 
> declaration, and shoehorn that declaration into the current 
> element's style attribute.
> 
> 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. "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.
> 
> In any case, I may not have a choice, but I wanted to ask if 
> anyone has any ideas on this issue. I have had incidents in 
> the past, where I was trying to solve a problem with a 
> spanner, and someone pointed out that a screwdriver would 
> address the issue better.
> 
> My XML version is 1.0
> 
> My XSLT Version is 1.0, as is my XPath version.
> 
> I am using the PHP 5 XSLTProcessor implementation (libxslt), 
> and <oXygen/> as my workshop.
> 
> I am using php:functionString callouts, and can probably use 
> them for this, but I wanted to find out if I just have it all 
> wrong, and there is a "pure" XSLT way of dealing with this. 
> The problem with using PHP callouts is that I can't run the 
> transform in <oXygen/>, which makes debugging a bit more difficult.
> 
> Any ideas?
> 
> Thanks in advance.
> 
> META: I am subscribed as a digest, so I won't be reading 
> responses for some time. Feel free to use the email addy in 
> my .sig to contact me directly if you want my immediate attention.
> 
> Chris Marshall
> chris at 
> getridofthiswholelongthingybecauseitstoconfusescrapers 
> littlegreenviper dot com http://www.cmarshall.net/

Current Thread