RE: [xsl] Re: 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] Re: whats the best way to create and use values for lookup (key-value) such that you can loop through it with limits
From: "SANWAL, ABHISHEK (HP-Houston)" <abhishek.sanwal@xxxxxx>
Date: Sat, 13 Sep 2003 19:58:44 -0500
Peter, & all other Grand Masters

I liked your example but there is one issue. Maybe I was not clear
enough in my previous explanation. (sometimes I confuse myself).

How can I use such a structure ( under another name space or under the
same (xsl:variable) and restrict its scope to a particular <template
match> that it is declared inside.

Basically for an output document that I am generating I have a template
match that allows me to generate tables on the fly using the content.
(Attached below.. this was posted by Wendell - I hope he is reading

Now in the bigger picture I have 

<template match "Chapter" >

<template match "Sections">

<template match "Paragraphs">

<template match "Matrix"> <!-- this is my table generator

Now my document has various chapters which have various sections where a
given section can have any number of matrices (matrix) and/or

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

<xsl:template match="Section[@SectionHeading='MySectionSomething1']">
... Variables..
.. Parameters...
.. apply templates xpath...

<xsl:template match="Section[@SectionHeading='MySectionSomething2']">
... Variables..
.. Parameters...
.. apply templates xpath...

Like so:

<xsl:template match="/Document/Chapter[@Name='ChapterName']">

then match 

<xsl:template match="Section[@SectionHeading='MySectionSomething']">

-	 Matrix  - (the following here are Parameters but if they can
even be variables ) I am not sure which one to use yet. But will define
my requirements below

- Matrix Data -
<xsl:with-param name="MCAllWidth" select=""/> 

<xsl:with-param name="MC1Width" select=""/>
<xsl:with-param name="MC2Width" select=""/>
<xsl:with-param name="MC3Width" select=""/>
<xsl:with-param name="MC4Width" select=""/>
<xsl:with-param name="MC5Width" select=""/>

- Head and Data Alignment -

<xsl:with-param name="HeadAlign" select="Center"/>
<xsl:with-param name="DataAlign" select="Left"/>

- Image Layout Frames -
<xsl:with-param name="ImageWidth" select="1"/>
<xsl:with-param name="ImageHeight" select="1"/>

<xsl:apply-templates select="."/>


Basically, this will allow US to keep the programmed stylesheets the
same but be able to apply different TABLE WIDTHS (matrix) and other
property attributes to the output elements.

For most of the other variables I can easily pick up the Variables. But
for the COLUMN WIDTH ... I want to add <col width ="{XXXXXX}"> tags and
be able to populate the widths using some kind of array or lookup table.


		<xsl:variable name="MatrixColWidths">
			<xsl:variable name="'1'" select="100"/>
			<xsl:variable name="'2'" select="200"/>
			<xsl:variable name="'3'" select="300"/>
			<xsl:variable name="'4'" select="400"/>

Or like this ( as shown on DPawsons FAQ as picked up from )
(Also the example test.xsl and class.xsl don't seem to work for me.. to
even test it out.. anyone suggest any fixes so I can see how it works)

<xsl:variable name="MatrixColWidths">
  <c colno="1" colw="100"/>
  <c colno="2" colw="75"/>
  <c codno="3" colw="80"/>
  <c codno="4" colw="75"/>

(I am not sure if variables can be defined as above. In essence I am
trying get an array kind of thing or a dictionary object or a key value
pair thing that WOULD BE "LOCAL" to that 
<xsl:template match="Section[@SectionHeading='MySectionSomething']">
and is placed DIRECTLY in the XSL inside that particular 
<xsl:template match="Section[@SectionHeading='MySectionSomething']">

so that I can pick up the values for the COLUMN WIDTHS for ANY and EVERY
"Matrix or Table" in that Section by iterating through that array or
whatever other structure/variable I can use (xsl or non-xsl namespace)
but LOCAL to the Section.

I don't really care how this is done as I am not sure if I can define
any such structure, keep it local as well as be able to ITERATE through
it to pull values.

Any genius solve this one ?? :)

I ve been trying to abstract this problem out to the list but have been
getting nowhere.

Abhishek Sanwal
HP - Houston Campus

-----Original Message-----
From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] 
Sent: Saturday, September 13, 2003 1:39 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Re: whats the best way to create and use values for
lookup (key-value) such that you can loop through it with limits

One of the basic XSLT design patterns is about maintaining useful
programming data structures within the XSLT code.

XSLT allows to have arbitrary global scope elements belonging to a
different from the XSLT namespace. Within such elements one can put any
structure, which may be used in the transformation.

Here's a simple example of this technique that shows how to solve the
current problem:

<xsl:stylesheet version="1.0"

 <xsl:output method="html" indent="yes"/>

 <xsl:variable name="vmaxCols" select="2"/>


  <xsl:template match="section1 | section2">

  <table border="1">
                    [local-name() = name(current())]/*
                                [position() &lt;= $vmaxCols]">

       <td width="{.}"><xsl:value-of select="."/></td>


When the above transformation is applied on this source.xml:

    <row col1="x1" col2="y1" col3="z1"/>
    <row col1="x2" col2="y2" col3="z2"/>
    <row col1="x3" col2="y3" col3="z3"/>
    <row col1="x4" col2="y4" col3="z4"/>
    <row mycol1="x1" mycol2="y1" mycol3="z1"/>
    <row mycol1="x2" mycol2="y2" mycol3="z2"/>
    <row mycol1="x3" mycol2="y3" mycol3="z3"/>

the wanted result is produced:

<table border="1">
      <td width="20">20</td>
      <td width="30">30</td>

<table border="1">
      <td width="30">30</td>
      <td width="20">20</td>


Dimitre Novatchev. -- the home of FXSL

"SANWAL, ABHISHEK (HP-Houston)" <abhishek.sanwal@xxxxxx> wrote in
> 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
> section.
>  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
> >
> How can I define the following so as to easily pickup values while
> iterating over the above value set defined in the XSL
> --------------------------
> whats the best way to create and use values for lookup such that you
> loop through it (like a key value pair that can be looped through )
> Basically if I have J=10 values defined
> MC0 = 10
> MC2 = 12
> MC3 = 9
> MC4 = 17
> ..
> etc.
> (these values must be stored somehow in the XSL file)
> How can I iterate and limit the pick up of values from 0 to I where I
> another variable that is less than J=10.
> 1st. How would you suggest storing the values ? variables ? params ?
> key()
> (I have not used key before.. just read somewhere that it can be used
> such)
> 2nd. If I use one of the above structures for iteration then how do I
> iterate through and limit the pickup of values to I ??
> I want to be able to define the use of the variables based on an
> Iterator.
> Abhishek Sanwal
> HP - Houston Campus
> abhishek.sanwal@xxxxxx
>  XSL-List info and archive:

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread