I have a XSLT question which follows on from the question I asked last week. XSL for Xml: Inserting specific classes using XSL
The challenge is to insert classes acc
Slightly modified XSLT from my answer: https://stackoverflow.com/a/13225163/787016. It adds class
attribute and uses substring-after
function to extract right part of section
attribute.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="k" match="page" use="@section"/>
<xsl:template match="/root">
<table>
<tr>
<xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]"/>
</tr>
<tr>
<xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]" mode="page"/>
</tr>
</table>
</xsl:template>
<xsl:template match="page">
<td class="{substring-after(@section, '_')}">
<xsl:value-of select="."/>
</td>
<td></td>
</xsl:template>
<xsl:template match="page" mode="page">
<td>
<xsl:value-of select="@number"/>
</td>
<td>
<xsl:value-of select="key('k', @section)[last()]/@number"/>
</td>
</xsl:template>
</xsl:stylesheet>