Re: [xsl] whats the best way to create and use values for lookup (key-value) such that you can loop through it with limits

Subject: Re: [xsl] whats the best way to create and use values for lookup (key-value) such that you can loop through it with limits
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Sep 2003 20:13:59 -0400
At 2003-09-12 18:36 -0500, SANWAL, ABHISHEK (HP-Houston) wrote:
How to pickup and insert values for individual column widths from
variables/params/(any other value holder with local scope) already
present in the XSL by limiting the number of values picked up to a
variable that defines the number of columns or a separate count ?

Basically I want to be able to specify in a template for a section the
values for the column widths for a table that is present in that
 that matches a table XML structure the

<xsl: template match section >
<!-- values for column widths -->
col 1 = 20
col 2 = 30
col 3 = 10
col 4 = 40
col 5 = "" <!-- may or may not be null ...that issue is open >

<apply-template table/>

<xsl: /template>

<xsl: template match "table">

<! Will use those values and apply them to the columns that it creates
dynamically based on the number of columns present in the XML structure

How can I define the following so as to easily pickup values while
iterating over the above value set defined in the XSL

Sounds like you want a side effect, which isn't available in XSLT.

You will have to repeat in your match of table the same calculation that you did in your match for section so that the variable of local scope in the table template rule has what you need.

This is not an uncommon need, but many people with a programming background still think in side-effects, especially changing global variables (the only variables that are in scope for more than one template rule).

If you can put your column calculations in a callable template, then you can call that callable template once in your match for section, and then again in your match for table. Each time you are going to your source node tree and recalculating something that you need in two places.

Remember: no changing variables in global scope, so if you need a calculated value in more than one template rule, you'll have to repeatedly calculate it in every template rule.

When your calculations are based on the source node tree (and note the current node list), then you are guaranteed to get the same result at all times that you do the calculation. If, however, your calculation is based on the current node list, then you'll have to be careful to ensure you are dealing with the same current node list each time you do the calculation.

Keys are based on the source node tree and not on a real-time calculation, so you've been mislead about keys.

I hope this helps.

............................. Ken

Next public European delivery:  3-day XSLT/2-day XSL-FO 2003-09-22
Next public US delivery:        3-day XSLT/2-day XSL-FO 2003-10-13
Instructor-led on-site corporate, government & user group training
for XSLT and XSL-FO world-wide:  please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 0-13-140374-5                               Definitive XSL-FO
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X               Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread