Subject: Re: [xsl] ordering and iteration problem From: "Hector Echegoyen" <hechegoyen@xxxxxxxxxxx> Date: Thu, 15 Nov 2001 16:24:44 -0500 |
<circuit-breaker-panel var="888"> <circuit-breaker column="1" row="1" height="2"> <amps>60</amps> <special>doubled</special> <description>heat pump</description> <circuit-breaker-panel> <circuit-breaker column="1" row="1" height="1"> <amps>99</amps> <description>the upper stairs</description> </circuit-breaker> </circuit-breaker-panel> </circuit-breaker> <circuit-breaker column="1" row="3" height="1"> <amps>15</amps> <description>upper stairs</description> </circuit-breaker> <circuit-breaker column="2" row="7" height="1"> <amps>15</amps> <description/> </circuit-breaker> <circuit-breaker column="2" row="8" height="2"> <amps>20</amps> <special>doubled</special> <description/> </circuit-breaker> </circuit-breaker-panel>
Jeni Tennison Wrote: ------------------------
My thinking is that I need to do something like
for each row for each column ooutput the <circuit-breaker> with that row and column
I'd probably do this using the Piez Method/Hack of having an xsl:for-each iterate over the correct number of random nodes and using the position of the node to give the row/column number.
You need to define some random nodes - I usually use nodes from the stylesheet:
And since you'll be iterating over them, you need some way of getting back to the data:
I've used two keys to get the relevant circuit breakers quickly. One just indexes them by column (this is so you can work out whether you need to add a cell or whether there's a circuit breaker from higher in the column that covers it). The other indexes them by row and column.
<xsl:key name="breakers-by-column" match="b:circuit-breaker" use="@column" /> <xsl:key name="breakers" match="b:circuit-breaker" use="concat(@row, ':', @column)" />
I've assumed that you've stored the maximum number of rows in a global variable called $max-row and the maximum number of columns in a global variable called $max-col. Here's the template that does the work:
<!-- template to give the cell for the circuit breaker --> <xsl:template match="b:circuit-breaker"> <td rowspan="{@height}"> <xsl:value-of select="b:amps" /> </td> </xsl:template>
If you don't like the 'one big template' approach, then you could split it down by applying templates to the row and column nodes in 'row' and 'column' modes to distinguish between the two.
_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] transform a link, Michael Kay | Thread | Re: [xsl] ordering and iteration pr, Jeni Tennison |
Re: [xsl] position of a child node, Carmelo Montanez | Date | [xsl] following-sibling in for-each, Christopher Eckert |
Month |