<?xml version="1.0" encoding="UTF-8"?>
<!-- 
    This XSL Stylesheet generates an html document from an XCCDF file.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cdf="http://checklists.nist.gov/xccdf/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="2.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/cdf:Benchmark">
        <html>
            <head>
                <title>SP 800-68</title>
            </head>
            <body>
                <h1 align="center">
                    <xsl:value-of select="./cdf:title"/>
                </h1>
                <h3 align="center">
                    <xsl:value-of select="./cdf:description"/>
                </h3>
                <hr align="center"/>
                <hr align="center"/>
                <h2>Table of Contents</h2>
                <xsl:for-each select="./cdf:Group[not(@hidden='true')]">
                    <xsl:variable name="section_number">
                        <xsl:value-of select="position()"/>
                    </xsl:variable>
                    <br/>
                    <xsl:value-of select="$section_number"/><i><xsl:text> -- </xsl:text><xsl:value-of select="./cdf:title"/></i><br/>
                    <br/>
                    <xsl:for-each select="./cdf:Group[not(@hidden='true')]">
                        <xsl:value-of select="$section_number"/><xsl:text>.</xsl:text><xsl:value-of select="position()"/><xsl:text> -- </xsl:text><xsl:value-of select="./cdf:title"/><br/>
                    </xsl:for-each>
                </xsl:for-each>
                <br/>
                <br/>
                <hr align="center"/>
                <hr align="center"/>
                <xsl:for-each select="./cdf:Group[not(@hidden='true')]">
                    <xsl:call-template name="print_group">
                        <xsl:with-param name="section_number" select="position()"/>
                    </xsl:call-template>
                    <hr align="center"/>
                    <hr align="center"/>
                </xsl:for-each>
            </body>
        </html>
    </xsl:template>
    <xsl:template name="print_group">
        <xsl:param name="section_number"/>
        <h3 align="left"><xsl:value-of select="$section_number"/> - <xsl:value-of select="./cdf:title"/></h3>
        <xsl:for-each select="./cdf:description">
            <p align="justify">
                <xsl:apply-templates/>
            </p>
        </xsl:for-each>
        <xsl:for-each select="./cdf:Rule[not(@hidden='true')]">
            <xsl:call-template name="print_rule">
                <xsl:with-param name="section_number" select="position()"/>
            </xsl:call-template>
        </xsl:for-each>
        <xsl:for-each select="./cdf:Group[not(@hidden='true')]">
            <xsl:call-template name="print_group">
                <xsl:with-param name="section_number" select="concat($section_number, '.', position())"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="print_rule">
        <xsl:param name="section_number"/>
        <table border="1" cellpadding="5" cellspacing="0" width="100%" style="table-layout:fixed">
            <colgroup span="3">
                <col width="120"/>
                <col width="200"/>
                <col width="*"/>
            </colgroup>
            <tr>
                <td>
                    <font size="-1"><xsl:value-of select="./cdf:reference[starts-with(., 'CCE')]"/></font>
                </td>
                <td>
                    <font size="-1"><xsl:value-of select="./cdf:title"/></font>
                </td>
                <td>
                    <font size="-1">
                        <xsl:for-each select="./cdf:description">
                            <p align="justify"><xsl:apply-templates/></p>
                        </xsl:for-each>
                    </font>
                </td>
            </tr>
        </table>
    </xsl:template>
     <xsl:template match="xhtml:p">
          <p/>
     </xsl:template>
     <xsl:template match="xhtml:br">
        <br/>
    </xsl:template>
    <xsl:template match="xhtml:strong">
         <strong><xsl:apply-templates/></strong>
    </xsl:template>
     <xsl:template match="xhtml:em">
          <em><xsl:apply-templates/></em>
     </xsl:template>
     <xsl:template match="xhtml:center">
        <center><xsl:apply-templates/></center>
    </xsl:template>
    <xsl:template match="xhtml:ul">
        <blockquote>
            <ul>
                <xsl:apply-templates/>
            </ul>
        </blockquote>
    </xsl:template>
    <xsl:template match="xhtml:ol">
        <xsl:variable name="type">
            <xsl:value-of select="@type"/>
        </xsl:variable>
        <blockquote>
            <ol type="{$type}">
                <xsl:apply-templates/>
            </ol>
        </blockquote>
    </xsl:template>
    <xsl:template match="xhtml:li">
        <li><xsl:apply-templates/></li>
    </xsl:template>
    <xsl:template match="xhtml:img">
        <xsl:variable name="src">
            <xsl:value-of select="@src"/>
        </xsl:variable>
        <xsl:variable name="title">
             <xsl:value-of select="@title"/>
        </xsl:variable>
         <img src="{$src}" title="{$title}"/>
        <br/>
         <xsl:value-of select="$title"/>
    </xsl:template>
</xsl:stylesheet>
