Skip to content Skip to sidebar Skip to footer

Sum Number Of Div In The Html Table Xslt

I need help with counting of div in table I need sum div in whole table and the result of sum put below table. Here is my output of table:

Solution 1:

-- edited in response to clarifications --

I would suggest you try it this way:

<xsl:variablename="count-points"><xsl:for-eachselect="/message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice//gml:pos"><n>1</n></xsl:for-each><xsl:for-eachselect="/message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice//gml:posList"><xsl:variablename="spaces"select="translate(normalize-space(.), '0123.456789.', '')" /><n><xsl:value-ofselect="ceiling(string-length($spaces) div 2)"/></n></xsl:for-each></xsl:variable><p>Count of Points: <xsl:value-ofselect="sum(exsl:node-set($count-points)/n)"/></p>

This would come after the </table> closing tag. You will also need to add the following namespace declaration to your stylesheet element:

xmlns:exsl="http://exslt.org/common"

Note: your attempt to count the div elements in the output cannot work; XSLT processes the input XML and does not have access to its own output.


Added:

Here's an alternative approach to the entire problem that eliminates the need to process the nodes twice - once to extract the points, and once to count them. And the output looks nicer, too.

XSLT 1.0

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:message="http://www.aixm.aero/schema/5.1/message"xmlns:gml="http://www.opengis.net/gml/3.2"xmlns:aixm="http://www.aixm.aero/schema/5.1"xmlns:exsl="http://exslt.org/common"exclude-result-prefixes="message gml aixm exsl"><xsl:outputmethod="html"encoding="UTF-8"/><xsl:templatematch="/"><!-- first-pass --><xsl:variablename="points"><xsl:for-eachselect="message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice"><groupdesignator="{aixm:designator}"><xsl:for-eachselect=".//gml:pos"><point><xsl:value-ofselect="."/></point></xsl:for-each><xsl:for-eachselect=".//gml:posList"><xsl:call-templatename="split"/></xsl:for-each></group></xsl:for-each></xsl:variable><xsl:variablename="points-set"select="exsl:node-set($points)" /><!-- output --><html><body><h2>Designated Points</h2><tableborder="1"><trbgcolor="#9acd32"><th>Designator</th><th>Coordinates</th></tr><xsl:for-eachselect="$points-set/group"><tr><tdrowspan="{count(point) + 1}"><xsl:value-ofselect="@designator"/></td></tr><xsl:for-eachselect="point"><tr><td><xsl:value-ofselect="."/></td></tr></xsl:for-each></xsl:for-each></table><p>Count of Points: <xsl:value-ofselect="count($points-set//point)"/></p></body></html></xsl:template><xsl:templatename="split"><xsl:paramname="text"select="normalize-space(.)"/><xsl:iftest="string($text)"><point><xsl:value-ofselect="substring-before($text, ' ')"/><xsl:text></xsl:text><xsl:value-ofselect="substring-before(substring-after(concat($text, ' '), ' '), ' ')"/></point><xsl:call-templatename="split"><xsl:with-paramname="text"select="substring-after(substring-after($text, ' '), ' ')"/></xsl:call-template></xsl:if></xsl:template></xsl:stylesheet>

Post a Comment for "Sum Number Of Div In The Html Table Xslt"