xsl-list
[Top] [All Lists]

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

2003-09-15 09:17:06
Abhishek,

For reasons explained by Ken, I don't think your solution will work the way you are describing; but I'm not sure you need the control over the scope of variables you say you require.....

At 08:58 PM 9/13/2003, you wrote:
Now my document has various chapters which have various sections where a
given section can have any number of matrices (matrix) and/or
paragraphs.

Now in the XSL for this I need to be able to HARD-CODE certain values
INTO A SECTION  that are to be used by all INNER TEMPLATES (namely,
Matrix, Paragraph, Items, SubItems etc.) ( But are NOT accessible to
other section matches

By this, do you mean hard-code these values into your source document, or into your stylesheet?

If into your source document, then each section would contain a particular set of nodes providing the parameters you want. So a section could look like:

<section SectionHeading='MySectionSomething1'>
<table-params>
  <col which="MC1Width">30</col>
  <col which="MC2Width">40</col>
  <col which="MC3Width">25</col>
  <col which="MC4Width">50</col>
  <col which="MC5Width">70</col>
</table-params>

Then in your stylesheet, the values are accessible from any template, given an XPath. So inside a table, you could always retrieve ancestor::section[1]/table-params/col[(_at_)which=$colName] ... or you can first bind ancestor::section/table-params/col to a variable colSpecs and then ask for $colSpecs[(_at_)which=$colName](_dot_)(_dot_)(_dot_)(_dot_)

If you want these values to be in the stylesheet, then use the lookup table technique Dimitre demonstrated....

<my:table-specs>
  <section SectionHeading='MySectionSomething1'>
    <col which="MC1Width">30</col>
    <col which="MC2Width">40</col>
    <col which="MC3Width">25</col>
    <col which="MC4Width">50</col>
    <col which="MC5Width">70</col>
  </section>
  <section SectionHeading='MySectionSomething2'>
    ....
  </section>
</my:table-specs>

Binding my:table-specs to a variable

<xsl:variable name="table-specs" select="document('')/*/my:table-specs"/>

You can always say

$table-specs[(_at_)SectionHeading=current()/ancestor::Section[(_at_)SectionHeading]/col[(_at_)which=$colName]

I hope that helps. Many times "parameterizing" something in XSLT doesn't actually require formal parameters or variables -- it's just retrieving node values (but those values have to be in a tree somewhere, or calculable).

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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