[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Replicating parent elements in table with children

Subject: Re: Replicating parent elements in table with children.
From: Mike Brown <mike@xxxxxxxx>
Date: Fri, 1 Nov 2002 13:36:36 -0700 (MST)
change parent elements
Alan K. Gay wrote:
> I have a parent <table> that can have zero to infinite <table1>.  I'm
> trying to create an html table that, for each occurrence of <table1>,
> has the contents of <table> and <table1>.  If there are no occurrences
> of <table1>, I still need the contents of <table>.   Below is sample
> input and desired output.  
> 
> I need help with the looping/xpath approach to make this happen.  Thanks
> in advance for any assistance.
> 
> <NewDataSet>
> 	<Table>
> 		<AvgScore>323</AvgScore>
> 		<Table1>
> 			<DeliveryID>4102</DeliveryID>
> 		</Table1>
> 		<Table1>
> 			<DeliveryID>4103</DeliveryID>
> 		</Table1>
> 		<Table1>
> 			<DeliveryID>4104</DeliveryID>
> 		</Table1>
> 	</Table>
> 	<Table>
> 		<AvgScore>975</AvgScore>
> 	</Table>
> </NewDataSet>
> 
> <table>
> <tr><td>323</td><td>4102</td></tr>
> <tr><td>323</td><td>4103</td></tr>
> <tr><td>323</td><td>4104</td></tr>
> <tr><td>975</td></tr>
> </table>

Hmm, not that hard. There are various combinations of apply-templates and
for-each that you could use to achieve the same result. Here's one of them:

<xsl:template match="/">
  <xsl:apply-templates select="NewDataSet/Table"/>
</xsl:template>

<xsl:template match="Table">
  <xsl:variable name="avg" select="string(AvgScore)"/>
  <xsl:for-each select="Table1/DeliveryID">
    <tr>
      <td>
        <xsl:value-of select="$avg"/>
      </td>
      <td>
        <xsl:value-of select="."/>
      </td>
    </tr>
  </xsl:for-each>
</xsl:template>

But let me guess.. MSXML2 / IE5, right? no xsl:variable, no string()...
take out the xsl:variable and change "$avg" to "../../AvgScore"

With some additional magic you could fill in the missing cells, but it's not
strictly necessary, with most browsers' forgiving table rendering engines.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.