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:variable name="count-points">
<xsl:for-each select="/message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice//gml:pos">
<n>1</n>
</xsl:for-each>
<xsl:for-each select="/message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice//gml:posList">
<xsl:variable name="spaces" select="translate(normalize-space(.), '0123.456789.', '')" />
<n>
<xsl:value-of select="ceiling(string-length($spaces) div 2)"/>
</n>
</xsl:for-each>
</xsl:variable>
<p>Count of Points: <xsl:value-of select="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:stylesheet version="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:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<!-- first-pass -->
<xsl:variable name="points">
<xsl:for-each select="message:AIXMBasicMessage/message:hasMember/aixm:Airspace/aixm:timeSlice/aixm:AirspaceTimeSlice">
<group designator="{aixm:designator}">
<xsl:for-each select=".//gml:pos">
<point>
<xsl:value-of select="."/>
</point>
</xsl:for-each>
<xsl:for-each select=".//gml:posList">
<xsl:call-template name="split"/>
</xsl:for-each>
</group>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="points-set" select="exsl:node-set($points)" />
<!-- output -->
<html>
<body>
<h2>Designated Points</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Designator</th>
<th>Coordinates</th>
</tr>
<xsl:for-each select="$points-set/group">
<tr>
<td rowspan="{count(point) + 1}">
<xsl:value-of select="@designator"/>
</td>
</tr>
<xsl:for-each select="point">
<tr>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
<p>Count of Points: <xsl:value-of select="count($points-set//point)"/></p>
</body>
</html>
</xsl:template>
<xsl:template name="split">
<xsl:param name="text" select="normalize-space(.)"/>
<xsl:if test="string($text)">
<point>
<xsl:value-of select="substring-before($text, ' ')"/>
<xsl:text> </xsl:text>
<xsl:value-of select="substring-before(substring-after(concat($text, ' '), ' '), ' ')"/>
</point>
<xsl:call-template name="split">
<xsl:with-param name="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"