Я бы использовал Javascript код внутри xsl-файла для создания страницы c HTML. Я пробовал некоторые решения, такие как использование CDATA внутри тега script, но ни одно из них не сработало. Файл XML выглядит следующим образом:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gruppo>
<nome>Casa Miles</nome>
<studente>
<id>sergio</id>
<nome>sergio</nome>
<cognome>zavota</cognome>
<scontrino>
<prodotto>
<nome>sapone piatti</nome>
<quantità>1</quantità>
<costo>3.3</costo>
<partecipante>
<id>stefano</id>
</partecipante>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<prodotto>
<nome>bresaola</nome>
<quantità>1</quantità>
<costo>5.5</costo>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<prodotto>
<nome>pasta</nome>
<quantità>10</quantità>
<costo>0.5</costo>
<partecipante>
<id>stefano</id>
</partecipante>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<prodotto>
<nome>pane</nome>
<quantità>3</quantità>
<costo>1.4</costo>
<partecipante>
<id>stefano</id>
</partecipante>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<data>2020-02-10</data>
<pagato>true</pagato>
</scontrino>
<pagamenti>
<partecipante>
<id>Stefano</id>
<quota>-33.0</quota>
</partecipante>
</pagamenti>
</studente>
<studente>
<id>stefano</id>
<nome>stefano</nome>
<cognome>Silvestri</cognome>
<scontrino>
<prodotto>
<nome>shampoo</nome>
<quantità>2</quantità>
<costo>2.3</costo>
<partecipante>
<id>stefano</id>
</partecipante>
</prodotto>
<prodotto>
<nome>insalata</nome>
<quantità>4</quantità>
<costo>0.5</costo>
<partecipante>
<id>stefano</id>
</partecipante>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<prodotto>
<nome>hamburger</nome>
<quantità>1</quantità>
<costo>3.6</costo>
<partecipante>
<id>stefano</id>
</partecipante>
</prodotto>
<prodotto>
<nome>pane</nome>
<quantità>3</quantità>
<costo>1.4</costo>
<partecipante>
<id>stefano</id>
</partecipante>
<partecipante>
<id>sergio</id>
</partecipante>
</prodotto>
<data>2020-03-10</data>
<pagato>true</pagato>
</scontrino>
<pagamenti>
<partecipante>
<id>Sergio</id>
<quota>33.0</quota>
</partecipante>
</pagamenti>
</studente>
</gruppo>
Файл xsl выглядит следующим образом:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="yes"/>
<xsl:key name="tableByDataScontrino" match="scontrino" use="data" />
<xsl:template match="/">
<html>
<head>
<title>HTML Document</title>
</head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
caption {
display: table-caption;
text-align: center;
}
</style>
<body>
<h2 align="center">Benvenuto <xsl:value-of select="gruppo/studente[nome='sergio']/nome"/></h2>
<h2 align="center">Gruppo: <xsl:value-of select="gruppo/nome"/> </h2>
<h2 align="center">Scontrini</h2>
<xsl:for-each select="gruppo/studente/scontrino[generate-id() = generate-id(key('tableByDataScontrino',data)[1])]">
<table>
<caption style="font-weight: bold;">Data: <xsl:value-of select="data"/></caption>
<tr>
<th>Nome</th>
<th>Quantità</th>
<th>Costo</th>
<th>Totale</th>
<th>Partecipanti</th>
</tr>
<xsl:for-each select="key('tableByDataScontrino',data)/prodotto">
<xsl:sort select="data" />
<tr>
<td><xsl:value-of select="nome"/></td>
<td><xsl:value-of select="quantità"/></td>
<td><xsl:value-of select="costo"/></td>
<td>Calcolato tramite Javascript</td>
<td>
<xsl:for-each select="partecipante">
<xsl:value-of select="."/>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
<h2 align="center" id="dataOdierna"></h2>
<table>
<tr>
<th>Studente</th>
<th>Quota</th>
</tr>
<tr>
<td><xsl:value-of select="gruppo/studente[nome='sergio']/pagamenti/partecipante/id"/></td>
<td><xsl:value-of select="gruppo/studente[nome='sergio']/pagamenti/partecipante/quota"/></td>
</tr>
</table>
<script>
currentDate = (new Date()).toLocaleDateString('en-GB');
document.getElementById("dataOdierna").innerHTML = "Pagamenti alla data: " + currentDate;
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Обратите внимание, что я попытался вставить скрипт в тело, но при использовании XSLT-процессор, скрипт не анализируется правильно.