<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <html>
            <head>
                <title>Nmap Detailed Scan Report</title>
                <style>
                    body {
                        font-family: Arial, sans-serif;
                        background-color: #f4f4f9;
                        color: #333;
                        margin: 0;
                        padding: 0;
                    }
                    h1, h2, h3 {
                        background-color: #007BFF;
                        color: white;
                        padding: 10px;
                        margin: 0;
                    }
                    h1 {
                        font-size: 24px;
                    }
                    h2 {
                        font-size: 18px;
                    }
                    h3 {
                        font-size: 16px;
                    }
                    table {
                        border-collapse: collapse;
                        width: 100%;
                        margin: 20px 0;
                    }
                    th, td {
                        border: 1px solid #ddd;
                        padding: 8px;
                        text-align: left;
                    }
                    th {
                        background-color: #007BFF;
                        color: white;
                    }
                    tr:nth-child(even) {
                        background-color: #f9f9f9;
                    }
                    tr:hover {
                        background-color: #f1f1f1;
                    }
                    ul {
                        list-style-type: none;
                        padding: 0;
                    }
                    li {
                        margin: 5px 0;
                    }
                </style>
            </head>
            <body>
                <h1>Nmap Detailed Scan Report</h1>
                <xsl:apply-templates select="nmaprun"/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="nmaprun">
        <h2>Scan Summary</h2>
        <p>Command: <xsl:value-of select="@args"/></p>
        <p>Start Time: <xsl:value-of select="@startstr"/></p>
        <p>Finished Time: <xsl:value-of select="@endstr"/></p>

        <xsl:for-each select="host">
            <xsl:call-template name="hostDetails"/>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="hostDetails">
        <h2>
            <xsl:value-of select="address[@addrtype='ipv4']/@addr"/>
        </h2>
        <h3>Host Information</h3>
        <ul>
            <li>MAC Address: <xsl:value-of select="address[@addrtype='mac']/@addr"/></li>
            <li>Vendor: <xsl:value-of select="address[@addrtype='mac']/@vendor"/></li>
            <li>Status: <xsl:value-of select="status/@state"/></li>
        </ul>

        <h3>Open Ports</h3>
        <table>
            <tr>
                <th>Port</th>
                <th>Protocol</th>
                <th>State</th>
                <th>Service</th>
                <th>Version</th>
                <th>Extra Info</th>
            </tr>
            <xsl:for-each select="ports/port">
                <tr>
                    <td><xsl:value-of select="@portid"/></td>
                    <td><xsl:value-of select="@protocol"/></td>
                    <td><xsl:value-of select="state/@state"/></td>
                    <td><xsl:value-of select="service/@name"/></td>
                    <td><xsl:value-of select="service/@version"/></td>
                    <td><xsl:value-of select="service/@extrainfo"/></td>
                </tr>
            </xsl:for-each>
        </table>

        <h3>OS Detection</h3>
        <ul>
            <xsl:for-each select="os/osmatch">
                <li>
                    OS Match: <xsl:value-of select="@name"/> (<xsl:value-of select="@accuracy"/>%)
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>
</xsl:stylesheet>

