[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: RE: How to implement an array
Well I got this far with this problem and is once again stumped. I am hoping one of you can detect the problem. Snippet from lookup.xml file: <TableStructures> <Item> <ItemLine>Required</ItemLine> <ItemAcct>Required</ItemAcct> <Option>Optional</Option> <ItemText>Required</ItemText> </Item> </TableStructures> Snippet from the xml file with the data: <Content> <CodeI>2</CodeI> <ID>6</ID> <TranNum>1</TranNum> <Table1> <Item> <ItemLine>3</ItemLine> <ItemAcct>6</ItemAcct> <Option>Contains Data1</Option> <ItemText>This is line 3</ItemText> </Item> <Item> <ItemLine>4</ItemLine> <ItemAcct>34</ItemAcct> <ItemText>This is line 4</ItemText> </Item> <Item> <ItemLine>5</ItemLine> <ItemAcct>34</ItemAcct> <Option>Contains Data2</Option> <ItemText>This is line 5</ItemText> </Item> </Table1> </Content> I am applying two templates, one creates the column heading and the other creates the table cells. The elements in the rows are optional...that is, an element could exist in one row and be absent in another. So to create the heading, I test all the elements of the parent node for existence of an element whose name matches that from the lookup table. If count > 0 then a heading is created for the element. I try to use the same logic to populate the individual cells in the second template...but it obviously is incorrect... <xsl:apply-templates select="//Content/Table1" mode="header"/> <xsl:apply-templates select="//Content/Table1" mode="celldata"/> Here are the templates: <xsl:template match="Table1" mode="header"> <xsl:variable name="Table1" select="."/> <!-- process each Item element from lookup.xml --> <tr> <xsl:for-each select="$Table1Struct"> <xsl:variable name="ItemName" select="string(name(.))"/> <xsl:if test="count($Table1//*[name(.)=$ItemName]) > 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="Table1" select="."/> <tr> <xsl:for-each select="./*"> <xsl:variable name="tval" select="text()"/> <xsl:for-each select="$Table1Struct"> <xsl:variable name="ItemName" select="string(name(.))"/> <xsl:if test="count($Table1//*[name(.)=$ItemName]) > 0"> <td><xsl:value-of select="$tval"/></td> </xsl:if> </xsl:for-each> </xsl:for-each> </tr> </xsl:template> Here's the output: ItemLine ItemAcct Option ItemText 3 3 3 3 6 6 6 6 Contains Data1 Contains Data1 Contains Data1 Contains Data1 This is line 3 This is line 3 This is line 3 This is line 3 4 4 4 34 34 34 This is line 4 This is line 4 This is line 4 5 5 5 5 34 34 34 34 Contains Data2 Contains Data2 Contains Data2 Contains Data2 This is line 5 This is line 5 This is line 5 This is line 5 Imrran --- Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote: > At 04:39 PM 2/12/2003, I wrote: > ><xsl:template match="events"> > > <xsl:variable name="events" select="."/> > > <!-- bind the current node to a variable so we > can get it back > > after we change context --> > > <tr> > > <xsl:for-each select="$months"> > > <xsl:variable name="monthname" > select="@name"/> > > <td> > > <xsl:choose> > > <xsl:when > > > test="not($events/event[@date[contains(.,$monthname)]])"> > > <xsl:text>?</xsl:text><!-- nbsp > --> > > </xsl:when> > > <xsl:otherwise> > > <xsl:apply-templates > > > select="$events/event[@date[contains(.,$monthname)]]"/> > > </xsl:otherwise> > > </xsl:choose> > > </td> > > </xsl:for-each> > > </tr> > ></xsl:template> > > Of course, looking now at my own code I can see the > xsl:choose could just > as well be: > > <xsl:apply-templates > > select="$events/event[@date[contains(.,$monthname)]]"/> > <xsl:if > test="not($events/event[@date[contains(.,$monthname)]])"> > <xsl:text>?</xsl:text><!-- nbsp --> > </xsl:if> > > Note: I do not, myself, have obsessive-compulsive > disorder. But living in > my brain is someone who does. > > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|