Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created November 5, 2019 09:46
Show Gist options
  • Save SebDeclercq/23b063cdbb192db75b882ec14420fd37 to your computer and use it in GitHub Desktop.
Save SebDeclercq/23b063cdbb192db75b882ec14420fd37 to your computer and use it in GitHub Desktop.
<html>
<body>
<table>
<thead>
<td>A</td>
<td>B</td>
<td>C</td>
</thead>
<tbody>
<tr>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>-1</td>
<td>2</td>
</tr>
</tbody>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<!-- **Tous elements et attributs *********************************** -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="attribute::*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="//thead">
<tr><xsl:copy-of select="*"/>
<th>Total</th></tr>
</xsl:template>
<xsl:template name="iter-tbody" match="//tbody">
<xsl:for-each select="tr">
<xsl:copy>
<xsl:apply-templates select="*"/>
<td><xsl:value-of select="sum(td)"/></td>
</xsl:copy>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment