Subject: Re: [xsl] too many columns From: Mike Brown <mike@xxxxxxxx> Date: Thu, 24 Oct 2002 13:00:00 -0600 (MDT) |
Gabi Bucataru wrote: > 1. > See, the thing is that i will never know how many of those A1, A2 elements > (and so on) I will have. Once it might be only 2, 4, who knows. So is there > a way that I can make the template dynamic? I mean this one (now I have 6 > A's there): > > <xsl:template match="A1|A2|A3|A4|A5|A6"> But you handle each of these elements the same way, so this template does not really need to change. What needs to change is how you arrive at this template: the selection of nodes for processing (xsl:apply-templates or xsl:for-each). Also, in the stylesheet I posted for you, I didn't mean to use mode="thead".. that was leftover from an experiment. > 2. > The second question is that I would like to start look into XSLT 1.0... Can > you please point me to a resource to learn that? I would like to make this > move. 1. The book "Beginning XSLT" by Jeni Tennison 2. The book "XSLT Reference" by Michael Kay 3. These free excerpts from other books: . http://www.ibiblio.org/xml/books/bible2/chapters/ch17.html . http://www.cranesoftwrights.com/training/#ptux-dl . http://www.oreilly.com/catalog/orxmlapp/chapter/index.html 4. http://www.vbxml.com/xsl/tutorials/intro/default.asp (decent tutorial) 5. http://www.zvon.org/xxl/XSLTutorial/Output/index.html (learn by example) You are lucky I didn't delete the XSLT 1.0 version of your stylesheet that I had dumbed down to make work with the WD-xsl namespace. I cannot imagine making this new one work with the WD-xsl namespace, though, because it makes use of XSLT 1.0 instructions like xsl:variable and functions like current(), local-name(), and string(). No one who uses XSLT would want to have to live without them! - Mike ____________________________________________________________________________ mike j. brown | xml/xslt: http://skew.org/xml/ denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/ <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" /> <xsl:template match="/"> <html> <head> <style type="text/css"> p.page {page-break-after: always} body {background-color:#cccccc; margin:0 font:MessageBox; font:Message-Box;} .TableBody {background: white; font-family: arial; font-size: 9px} .TableHeading {border-top-width:1; border-left-width:1; border-bottom-width:1; border-right-width:1; border-right-color:black; border-bottom-color:black; border-style:outset; font-family:verdana; font-size:10px; background-color:#cccccc} </style> <!-- rest of head here --> </head> <body> <xsl:apply-templates select="XMLData/Page" /> </body> </html> </xsl:template> <xsl:template match="Page"> <p class="page"> <table style="background: black" cellspacing="1" width="600"> <thead> <xsl:apply-templates select="Columns/Column" /> </thead> <tbody class="TableBody"> <xsl:apply-templates select="People/Person" /> </tbody> </table> </p> </xsl:template> <xsl:template match="Column"> <th nowrap="yes" class="TableHeading"> <xsl:choose> <xsl:when test="string(Caption)"> <xsl:value-of select="Caption" /> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </th> </xsl:template> <xsl:template match="Person"> <tr> <xsl:variable name="thisPerson" select="." /> <xsl:for-each select="../../Columns/Column"> <xsl:variable name="thisColumnData" select="$thisPerson/Data/*[local-name()=current()/XMLNodeName]" /> <xsl:choose> <xsl:when test="$thisColumnData"> <xsl:apply-templates select="$thisColumnData" /> </xsl:when> <xsl:otherwise> <td valign="top" style="color:#000000;background-color:#FFFFFF"> </td> </xsl:otherwise> </xsl:choose> </xsl:for-each> </tr> </xsl:template> <xsl:template match="A1|A2|A3|A4|A5|A6"> <xsl:variable name="color"> <xsl:if test="@color"> <xsl:value-of select="@color"/> </xsl:if> </xsl:variable> <xsl:variable name="bgcolor"> <xsl:if test="@fond"> <xsl:value-of select="@fond"/> </xsl:if> </xsl:variable> <td valign="top"> <xsl:attribute name="style"> <xsl:text>color:#</xsl:text> <xsl:choose> <xsl:when test="$color != ''"> <xsl:value-of select="$color"/> </xsl:when> <xsl:otherwise>000000</xsl:otherwise> </xsl:choose> <xsl:text>;background-color:#</xsl:text> <xsl:choose> <xsl:when test="$bgcolor != ''"> <xsl:value-of select="$bgcolor"/> </xsl:when> <xsl:otherwise>FFFFFF</xsl:otherwise> </xsl:choose> <xsl:text>;</xsl:text> </xsl:attribute> <xsl:choose> <xsl:when test="string(.)"> <xsl:value-of select="." /> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </td> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] too many columns, Gabi Bucataru | Thread | Re: [xsl] too many columns, Gabi Bucataru |
RE: [xsl] Re: Accounting for Arbitr, McNally, David | Date | Re: [xsl] LaTeX -> RTF, is XSLT the, MindFuq |
Month |