Subject: [xsl] Adding Several Numerical Attribute Values into One Attribute From: "Joe Heidenreich" <HeidenreichJ@xxxxxxxx> Date: Mon, 11 Jul 2005 09:03:02 -0400 |
Hi, I'm trying to translate an xml table into html and I want to offset the table head with a horizontal rule that spans the entire width of the table. So I need to generate a colspan attribute value that consists of all other colspan attribute values. If the colspan attribute is missing or "NaN", add one to the value. I also have to use XML 1.0. For example: <tr> <th colspan="1"></th> <th colspan="2"></th> <th colspan="NaN"></th> </tr> I would need a colspan attribute that contains the value of 4. I know that variables and parameters in XSLT don't work the same as a coder is used to. I've looked at a few examples that simulate an incrementing variable through a parameter so you can process a loop, which I believe to be a similar situation to the one that I'm dealing with, except I need to add a variant value depending on the attribute. Here is an example of my XSL that doesn't work: <xsl:template match="thead"> <tr> <td> <xsl:attribute name="colspan"><xsl:call-template name="get-col-span"/></xsl:attribute> <hr noshade="noshade"/> </td> </tr> <xsl:apply-templates/> </xsl:template> <xsl:template name="get-col-span"> <xsl:apply-templates select="tr[1]" mode="build-col-span"/> </xsl:template> <xsl:template match="tr" mode="build-col-span"> <xsl:param name="colspan_var"/> <xsl:call-template name="get-th"> <xsl:with-param name="colspan_var">0</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template match="th" name="get-th"> <xsl:choose> <xsl:when test="@colspan != ''"> <xsl:choose> <xsl:when test="@colspan != 'NaN'"> <xsl:param name="colspan_var" select="$colspan_var + @colspan"/> </xsl:when> <xsl:otherwise> <xsl:param name="colspan_var" select="$colspan_var + 1"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:param name="colspan_var" select="$colspan_var + 1"/> </xsl:otherwise> </xsl:choose> <xsl:variable name="next" select="following-sibling::th[1]"/> <xsl:choose> <xsl:when test="!($next)"> <xsl:value-of select="$colspan_var"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="get-th"> <xsl:with-param name="colspan_var"><xsl:value-of select="$colspan_var"/></xsl:with-param> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> I know there is a problem with how I'm setting up my parameter value in the get-th template. I'm not even sure if I'm addressing this problem in the proper manner. Any help would be greatly appreciated. Thanks!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Integrating XInclude in e, David Carlisle | Thread | Re: [xsl] Adding Several Numerical , David Carlisle |
Re: [xsl] Optimising multiple docum, G. Ken Holman | Date | [xsl] Using variables in template m, Geert Josten |
Month |