At 2004-01-22 13:09 -0500, Govil, Anoop (Contractor) wrote:
>From what I understand, your problem seems to be same as mine: Please check
my posting today: Linear counting problem in nested loop.
I guess you have a nested loop within a loop (just like I have and you need
to set the ids as a linear counter value). I am in the same boat if I
understood you right.
Yes, you are both in the boat of thinking "counters". My students come in
to my courses with the same misconception about XSLT. When you try to
treat XSLT like a programming language, you end up going through terrible
contortions with ugly and poorly performing stylesheets.
The "nature of writing XSLT stylesheets" parallels the "nature of working
with hierarchies" and the node tree from an XML document is a
hierarchy. Think of your problems as examinations of the hierarchy, and
try to abandon classical programming techniques as they do not apply.
If you need something unique about a node, consider "where is it in the
hierarchy?"
If it is globally unique when unique amongst its siblings, or unique in the
selection of nodes in the select expression, you can probably use
position() or a simple count().
If it is not globally unique when examined amongst its siblings, consider
its ancestry and what components of the ancestry you can use for uniqueness.
Remember that every time you process a new node, you are in a new context
that is distinct from the context of all other source tree nodes ... what
can you do with that node that is different?
Consider chapter counting: the classical programming technique is to set a
variable and increment it. In XSLT you, instead, query the processor and
ask "Which source tree chapter node is being processed?" and expose the
return value to the result as the output chapter number. The next time
around, ask again; don't try to keep it around. The classical programming
models have side effects, while XSLT does not.
I hope someone out there (XSL Guru) may be able to solve our issues.
Sorry, my car license plate reads "XML Guru", not "XSL Guru" (picture in my
web site bio and entry in the Internet License Plate Gallery), but
hopefully this commentary above still helps.
...................... Ken
p.s. BTW, it happens that XSLT *is* Turing Complete, but it is a functional
programming language without side effects and you have to treat it that way.
--
Public courses: sign up for one or both soon to reserve your seat!
Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Washington, DC: 2004-03-15 San Francisco, CA: 2004-03-22
Hong Kong, China: 2004-05-17 Bremen, Germany: 2004-05-24
World-wide on-site corporate, government & user group XML training
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list