Re: [xsl] Column Heads and Column Data problem ??

Subject: Re: [xsl] Column Heads and Column Data problem ??
From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx>
Date: Thu, 21 Aug 2003 22:22:11 -0400
Hi Wendell,

Thanks a lot for replying and corroborating that the problem is tough.

Yeah initially i thougth it will not be possible using xslt. But you gurus 
have said that everything is possible and i believe in experience.

Yeah my xsl input is large which i can not post and when i composed  my email 
last time it tool me 45 minutes to pose the exact problem.

Yeah the solution which i have figured out appears to be simple and i am more 
of procedural programming knida guy thats y written my algorithm like that. In 
the first step only i found many problems about which i have emailed to list.

Yeah you are absolutely rigth that i have to decompose my problem into small 
problems and solve it.

You are absolutely rigth my subroutine is very difficult to implement in xslt. 
I am facing the same problem which you have qouted like 
1) Getting the node with maximum number of attributes.
2) Storing the final value in the variable
3) If i am able to get the above two things then i can think of outputing it 
with other hard coded strings.

Well, thanks a lot for your valuable advice. I am trying hard to solve it. Let 
see will i be able to get it done. I don't like to give you easily.

Thanks once again.

Regards,
Dipesh


Date: Thu, 21 Aug 2003 12:04:12 -0400
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Subject: Re: [xsl] Column Heads and Column Data problem ??

Dipesh,

Your last post actually indicates you are making good progress on building 
your solution.

Although I can't demonstrate specific algorithms (as I said I find myself 
rather short of time this week), I can offer some general advice that I 
believe applies to your case (please forgive the length of the post; as they 
say "I didn't have time to make it short"):

1. Recognize that although, as we've said, XSLT can do this problem, keep in 
mind that it's a *hard* problem, not at beginner-level at all -- if only 
because it requires an intimate understanding of your data set and what you 
are trying to do with it, which none of us have.

2. It appears from your problem description that you want a solution that is 
both generalized (accept arbitrary inputs within a certain range), and can be 
"tuned" to a particular data set -- to do things like establish what order you 
want your output in, etc. This makes the problem harder, of course (though not 
impossible).

3. This approach certainly won't get you far:

> In other programming language it should be something like this:
>
> Variable colHeaderForTable1;
> Variable maxColNoForTable1=0;
> For each //Table1
> variable temp = count(no. of columns in this table);
> if (temp > maxColNoForTable1)
> colHeaderForTable1={"ParentID", "SelfID",Getting each column name
>followed by seperator}
> End of For
> Output value of colHeaderForTable1

The reason you'll find it frustrating to try to implement this in XSLT is that 
the language just doesn't work like this, and doesn't have these constructs. 
It is not an imperative, procedural language, but rather declarative and 
functional. That is, it generally does not work by providing a set of commands 
to the processor; rather, it simply *declares*, for a given input, what a 
given output will be. Now in problems like yours, which involve lots of 
querying, testing and rearranging, even an XSLT program will dictate 
"procedures". Yet it will typically *not* do this by using methods, such as 
looping or managing "state" generally, common in languages with which you are 
likely familiar.

For example, your subroutine above is basically a simple query for "give me 
the values in the table with the most columns", which is a compound of "give 
me the table with the most columns; now give me its values". XSLT would 
probably have something like a variable declaration that assigned to a 
variable the table with the most columns (the first query), followed by a 
simple processing of that variable to get its values (the second). (It's 
interesting, because stated this way it's clear to an experienced XSLT user 
why this is hard to do -- XSLT 1.0 gives you no function to determine which 
table has the most columns; yet there are several ways to do it known to 
readers of this list.)

One of the strange ironies of this powerful technology is that it is therefore 
often easier for people to learn who have *no* programming background, than 
for those who have enough background to know how these problems are solved 
using other languages, and who therefore fall back on what they know. 
Unfortunately, this only makes it worse for them. (In my experience, people 
who take very quickly and easily to XSLT either have little or no programming 
background, or have a very deep one.)

Accordingly, I think you would be very well served by taking some time for a 
crash course in XSLT fundamentals -- seeing how XSLT approaches problems that 
are easier than yours (especially problems that are easier for it, but that 
would be harder in a procedural language). If you have the time to give, that 
is. (If you don't, you're kind of up the creek without a paddle.)

Also, take a good look at documentation on problems similar to yours, some of 
which you'll find at www.jenitennison.com (on grouping, which is a problem 
area that encompasses your problem) and in the XSL FAQ at 
http://www.dpawson.co.uk/xsl/sect2/sect21.html.

4. Several of the things you are trying to do, such as determining which table 
has the most columns, involve solutions that are not obvious. This is another 
reason your learning curve is particularly long and steep. Breaking the 
problem down into simpler ones is likely to help you move forward.

Also, it will help you to ask the list more focused, answerable questions. At 
this point, it is as though you are asking "how to I cook a seven-course 
meal?" -- which we can't really explain to you even if you give us the entire 
menu. It is much easier to answer questions like "how do I chop the onions".

I wish I could help more, but I'm afraid I'm doing all I can given limits on 
time and the bandwidth of a mailing list.... but I'm sure if you can break 
your problem down into smaller pieces, you'll find it easier to get help.

Cheers,
Wendell


======================================================================
Wendell Piez wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
- ----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread