cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John EM Mitchell <jo...@cs.stir.ac.uk>
Subject Re: conditional </tr><tr> generation ???
Date Tue, 20 Jun 2000 16:56:50 GMT
> <table>
>   <xsl:for-each select="group">
>     <xsl:if test="position() mod 4 = 0">
>       <tr>
>         <xsl:apply-templates select="."/>
>         <xsl:apply-templates select="following-sibling::*[position() = 1]"/>
>         <xsl:apply-templates select="following-sibling::*[position() = 2]"/>
>         <xsl:apply-templates select="following-sibling::*[position() = 3]"/>
>       </tr>
>     </xsl:if>
>   </xsl:for>
> </table>
> 
> <xsl:template match="element">
>   <td>
>      ...
>   </td>
> </xsl:template>
> 
> assuming:
> <group>
>   <element/>
>   <element/>
>   ...
>   <element/>
> </group>

I've only just joined the list, so apologies if this is
off-topic, but I guess the original poster wanted to 
generate a table on the fly.
Bouncing 
www.hcrc.ed.ac.uk/~dmck/xslt-tutorial.html
off 
http://metalab.unc.edu/xml/books/bible/examples/14/index.html

I cobbled together the following .xsl , which produces a html
table with table headings and righthand-headings if applied to
http://metalab.unc.edu/xml/books/bible/examples/14/14-1.xml ,
for example.

It's not beautiful, but it does work :-)
cheers,
john

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v3.0 NT (http://www.xmlspy.com) by John 
EM Mitchell  -->
<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="PERIODIC_TABLE">
	<HTML>
		<h2>
			<xsl:value-of select="local-name()"/>
		</h2>
		<table bgcolor="GREEN">
			<xsl:call-template name="ATOMTH"/>
			<xsl:apply-templates select="ATOM"/>
		</table>
	</HTML>
</xsl:template>
<xsl:template match="ATOM">
	<tr>
		<xsl:apply-templates select="DENSITY">
			<!--really need this to be variablised....  Also nd to stop its
duplication downstairs - presumably by making the test down in the
choose suit the level.  but that will mean it won't be proc first! 
arrgh variablisation must be the answer-->
		</xsl:apply-templates>
		<xsl:for-each select="*">
			<!--I think all this is eq2 to just apply-templates!  hey ho.  But of
course the apply-temps wd bh2b outwith a for-each, in order to be at the
right level.  an apply-templates here wd be all wrong, for anything but
DENSITY-->
			<xsl:choose>
			<xsl:when test="local-name()='ATOMIC_WEIGHT'">
				<xsl:call-template name="WEIGHT_CELL"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="OTHER_CELL"/>
			</xsl:otherwise>			  
			</xsl:choose>
		</xsl:for-each>
	</tr>
</xsl:template>
	<xsl:template name="ATOMTH">
		<tr>
			<!--This one's trying to do the THs. as opp to the TRs, so has to be
a name template in order that it be called only once. WORKS ok, as long
as the final ATOM in the table has all the ATTS- conforms to the DTD, in
other words.  Next is to get proper blank cells in for Jobinium, so
everythings' in the right colm.  That'll be in template match = ATOM, I
sd think-->
		<xsl:for-each select="ATOM">
			<xsl:if test="position()=last()">
				<xsl:for-each select="*">
					<th>
					<xsl:value-of select="local-name()"/>
					</th>
				</xsl:for-each>
			</xsl:if>
		</xsl:for-each>
	</tr>
</xsl:template>
<xsl:template name="WEIGHT_CELL">
	<td>
		<font size="20" color="blue">
			<i>
				<xsl:value-of select="."/>
			</i>
		</font>
	</td>
	<xsl:text/>
</xsl:template>
<xsl:template name="OTHER_CELL">
	<td>
		<center>
			<font size="2" color="yellow">
				<i>
					<xsl:value-of select="."/>
				</i>
			</font>
		</center>
	</td>
	<xsl:text/>
</xsl:template>

<xsl:template name="RH">
	<th align="right" width="20%">
		<font size="34" color="black">
			<xsl:value-of select="."/>
		</font>
	</th>

</xsl:template>
<xsl:template match="DENSITY">
	<th width="50%">
		<xsl:value-of select="."/>
	</th>
</xsl:template>

	<!--- ?how 2 match on this-->
	<xsl:variable name="rh">NAME</xsl:variable>
</xsl:stylesheet>

Mime
View raw message