Namespace / elements statistics

exercise No. 21

Q:

Consider the following XML document example:

<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">

    <xsl:output method="xhtml"/>

    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>SVG</title>
                <meta charset="utf-8" />
            </head>
            <body>
                <h2>HTML5 SVG Circle</h2>
                <p>Starting a simple test.</p>
                <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
                    <circle id="redcircle" cx="50" cy="50" r="50" fill="red" />
                </svg>
                <p>Ending a simple test.</p>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="*">
        <xsl:message>
            <xsl:text>No rule defined for element '</xsl:text>
            <xsl:value-of select="name(.)"/>
            <xsl:text>'.</xsl:text>
        </xsl:message>
    </xsl:template>

</xsl:stylesheet>

The above sample document does contain elements belonging to three different namespaces:

http://www.w3.org/1999/XSL/Transform

Having namespace prefix xsl.

http://www.w3.org/1999/xhtml

Having no namespace prefix.

http://www.w3.org/2000/svg

Having no namespace prefix.

Write a Jdom application which generates statistical data like being represented by HTML to the right.

Your application is expected to operate on arbitrary XML input documents.

Providing suitable unit tests is an inherent part of this exercise!

Tip

You may obtain a collection of all nodes as a result of the XPath expression //*. Then construct a Map<String, Set<...>> having namespaces as keys and sets of element names among with frequencies as values. Mind an appropriate equals() definition!

A: