Subject: RE: [xsl] using node fragments From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx Date: Mon, 14 Apr 2003 17:03:21 +0100 |
Hi Woody, > I have this section of an xml file that needs to be rendered > to a table > > <TGROUP> > <COLSPEC COLNUM="1" COLNAME="1" COLWIDTH="0.713in"/> > <COLSPEC COLNUM="2" COLNAME="2" COLWIDTH="1.179in"/> > <COLSPEC COLNUM="3" COLNAME="3" COLWIDTH="1.272in"/> > <COLSPEC COLNUM="4" COLNAME="4" COLWIDTH="3.283in"/> [...] > Problem here is that I need to change the COLWIDTH into > percentages to > render out to the table. if you want to avoid using node-set() then you will need a recursive template to get you the total column width from which to calculate the percentages. To get rid of "in" etc. you can use translate(@COLWIDTH,"abcdefghijklmnopqrstuvwxyz","") to get just the numerical value. <xsl:template name="get_total_width"> <xsl:param name="nodes" select="/.."/> <xsl:param name="sub_total" select="0"/> <xsl:variable name="width" select="number( translate($nodes/@COLWIDTH, 'abcdefghijklmnopqrstuvwxyz', '') )"/> <xsl:choose> <xsl:when test="count($nodes) > 1"> <xsl:call-template name="get_total_width"> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> <xsl:with-param name="sub_total" select="$sub_total + $width"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$sub_total + $width"/> </xsl:otherwise> </xsl:choose> </xsl:template> then you can call it to get the total for the table you're looking at: <xsl:variable name="total_width"> <xsl:call-template name="get_total_width"> <xsl:with-param name="nodes" select="TGROUP/COLSPEC[@COLNUM]"/> </xsl:call-template> </xsl:variable> and as long as the variable's in scope, use it to calculate the percentage. hth, Tom SW XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] using node fragments, Andrew Welch | Thread | RE: [xsl] using node fragments, Passin, Tom |
RE: [xsl] using node fragments, Andrew Welch | Date | RE: [xsl] using node fragments, Passin, Tom |
Month |