p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Two-Column Output


Message #1 by "Mains, Brian" <bmains@s...> on Mon, 17 Jun 2002 12:26:12 -0400
If you use mode="cell" in the apply-templates call, as I suggested, then
you also need to use it in the xsl:template declaration, otherwise they
won't match.

I make a habit of using an explicit mode when writing this kind of
construct, otherwise there is a danger of writing a non-terminating
recursion, which can be hard to debug.

Michael Kay
Software AG
home: Michael.H.Kay@n...
work: Michael.Kay@s... 

> -----Original Message-----
> From: Brian Mains [mailto:bmains@s...] 
> Sent: 18 June 2002 13:05
> To: P2P_XSLT
> Subject: [xslt] RE: Two-Column Output
> 
> 
> Hello,
> 
> I've added more data, so my XML looks like:
> 
> <Data>
> 	<Car>
> 		<Manufacturer>Subaru</Manufacturer>
> 		<Model>Impreza WRX</Model>
> 		<Horsepower>227</Horsepower>
> 		<Liter>2.0</Liter>
> 		<Color>Rally Blue</Color>
> 	</Car>
> 	<Car>
> 		<Manufacturer>Nissan</Manufacturer>
> 		<Model>350Z</Model>
> 		<Horsepower>280</Horsepower>
> 		<Liter>3.0</Liter>
> 		<Color>Silver</Color>
> 	</Car>
> 	<Car>
> 		<Manufacturer>Toyota</Manufacturer>
> 		<Model>Tacoma Off-Road</Model>
> 		<Horsepower>200</Horsepower>
> 		<Liter>3.0</Liter>
> 		<Color>Black</Color>
> 	</Car>
> 	<Car>
> 		<Manufacturer>Suzuki</Manufacturer>
> 		<Model>4-Runner</Model>
> 		<Horsepower>227</Horsepower>
> 		<Liter>2.0</Liter>
> 		<Color>Yellow</Color>
> 	</Car>
> 	<Car>
> 		<Manufacturer>Honda</Manufacturer>
> 		<Model>Civic</Model>
> 		<Horsepower>140</Horsepower>
> 		<Liter>2.0</Liter>
> 		<Color>White</Color>
> 	</Car>
> 	<Car>
> 		<Manufacturer>Acura</Manufacturer>
> 		<Model>Integra</Model>
> 		<Horsepower>205</Horsepower>
> 		<Liter>3.0</Liter>
> 		<Color>Black</Color>
> 	</Car>
> </Data>
> 
> I've created a stylesheet that looks like:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> 	<xsl:template match="/">
> 		<xsl:for-each select="/Data/Car[position() mod 
> 2 = '1']">
> 		  <tr>
> 		    <xsl:apply-templates select="." mode="cell"/>
> 		    <xsl:apply-templates 
> select="following-sibling::Car" 
> mode="cell"/>
> 		  </tr>
> 		</xsl:for-each>
> 	</xsl:template>
> 	
> 	<xsl:template match="Car">
> 		<td>
> 			<xsl:value-of select="Manufacturer"/>
> 		</td>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> Using the MSXML4 parser, I get an output of:
> 
> SubaruImpreza WRX2272.0Rally 
> BlueNissan350Z2803.0SilverToyotaTacoma Off-
> Road2003.0BlackSuzuki4- 
> Runner2272.0YellowHondaCivic1402.0WhiteAcuraIntegra2053.0Black 
> ToyotaTacoma Off-Road2003.0BlackSuzuki4- 
> Runner2272.0YellowHondaCivic1402.0WhiteAcuraIntegra2053.0Black 
> HondaCivic1402.0WhiteAcuraIntegra2053.0Black 
> 
> It's running all together, plus I think it isn't even getting to the 
> template match="car" statement.
> 
> Any ideas?
> 
> Thanks.
> 


  Return to Index