def decrease_heading(doc, path=None):
    """Decrease heading number except specified element (by xpath).

    That is, ``<h1>`` becomes ``<h2>``, ... ``<h5>`` becomes ``<h6>``.
    (``<h6>`` is kept as is).
    It is for prettier Table of Contents,
    TOC is usually copied from heading structure.
    A basic use case is when the document has multiple ``<h1>``.
    You don't want those to clutter TOC tree,
    want only one of them on top.

    >>> el = fromstring('<div><h1>aaa</h1><h1 class="b">bbb</h1><h2>ccc</h2></div>')  # noqa: E501
    >>> decrease_heading(el, './@class="b"')
    >>> tostring(el)
    '<div><h2>aaa</h2><h1 class="b">bbb</h1><h3>ccc</h3></div>'
    """
    for i in range(5, 0, -1):
        for el in doc.xpath('//h' + str(i)):
            el.tag = 'h' + str(i + 1)
    if not path:
        return
    for i in range(2, 7):
        for el in doc.xpath('//h' + str(i)):
            if el.xpath(path):
                el.tag = 'h1'
                return
