RE: RE: [xsl] How to implement an array

Subject: RE: RE: [xsl] How to implement an array
From: Imrran Wahid <devguy2003@xxxxxxxxx>
Date: Fri, 14 Feb 2003 05:33:36 -0800 (PST)
Well I came upon another hurdle to cross. I have
several different tables defined in lookup.xsl. I
would like to use the two templates (below) to create
separate tables for them. Instead of writing different
templates for each table, how do I use parameters in
the solution? I was thinking along the lines of having
the one template for creating the header and the one
for creating the cells with data, and passing the
parent node containg the rows into these templates to
create the different tables.

I tried with it for some time last night but seemed to
be going around in cirlces. Any ideas?

Here are the templates:

<xsl:template match="Table1" mode="header">
  <xsl:variable name="Table1" select="."/>
  <tr>
  <xsl:for-each select="$Table1Struct">
    <xsl:variable name="ItemName"
select="string(name(.))"/>
    <xsl:if test="count($Table1//*[name(.)=$ItemName])
&gt; 0">
      <td><xsl:value-of select="$ItemName"/></td>
    </xsl:if>
  </xsl:for-each>
  </tr>
</xsl:template>

<xsl:template match="Table1/Item" mode="celldata">
   <xsl:variable name="thisitem" select="."/>
     <tr>
       <xsl:for-each select="$Table1Struct">
         <td>
           <xsl:value-of
select="$thisitem/*[name()=name(current())]"/>
           <!-- selects that child of the Item whose
name is the name of
                the $Table1Struct node we're looking
at -->
           <xsl:if
test="not($thisitem/*[name()=name(current())])">
</xsl:if>
           <!-- if there is none, gives us a space -->
         </td>
       </xsl:for-each>
   </tr>
</xsl:template>

And apllying the templates:

    <table cellpadding="1" cellspacing="0" border="1"
bordercolor="#000000">    
      <xsl:apply-templates select="//Content/Table1"
mode="header"/>
      <xsl:apply-templates select="//Content/Table1"
mode="celldata"/>
    </table> 


Thanks.

Imrran 
--- Imrran Wahid <devguy2003@xxxxxxxxx> wrote:
> Wendell,
> It's a neat solution. Thanks for the time you took
> to
> help me resolve this along the way. It's been
> bugging
> me for a while. Now I'm off to implement it with
> several different tables being defined in the lookup
> file.
> 
> Once again, thanks to you and all who make this list
> a
> healthy resource for learning.
> 
> Imrran
> 
> > 
> > It's tricky and confusing. In order to get the
> logic
> > right, you actually 
> > have to invert it. First iterate over the lookup
> > nodes in $Table1Struct, 
> > creating a <td> for each one. Then its value: you
> > want the value of that 
> > child of your Item that passes your name test; if
> > there is none, presumably 
> > (this being HTML) you want a placeholding
> > non-breaking space.
> > 
> > This template will do this:
> > 
> > <xsl:template match="Table1/Item" mode="celldata">
> >    <xsl:variable name="thisitem" select="."/>
> >      <tr>
> >        <xsl:for-each select="$Table1Struct">
> >          <td>
> >            <xsl:value-of
> > select="$thisitem/*[name()=name(current())]"/>
> >            <!-- selects that child of the Item
> whose
> > name is the name of
> >                 the $Table1Struct node we're
> looking
> > at -->
> >            <xsl:if
> >              
> >
>
test="not($thisitem/*[name()=name(current())])"> </xsl:if>
> >            <!-- if there is none, gives us a space
> > -->
> >          </td>
> >        </xsl:for-each>
> >    </tr>
> > </xsl:template>
> > 
> > Please ask about anything mysterious here.
> > 
> > Cheers,
> > Wendell
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Shopping - Send Flowers for Valentine's Day
> http://shopping.yahoo.com
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

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


Current Thread