public static function generateAttribute(string $name, $value): string
  {
    $html = '';

    switch ($name)
    {
      // Boolean attributes.
      case 'autofocus':
      case 'checked':
      case 'disabled':
      case 'hidden':
      case 'ismap':
      case 'multiple':
      case 'novalidate':
      case 'readonly':
      case 'required':
      case 'selected':
      case 'spellcheck':
        if (!empty($value))
        {
          $html = ' ';
          $html .= $name;
          $html .= '="';
          $html .= $name;
          $html .= '"';
        }
        break;

      // Annoying boolean attribute exceptions.
      case 'draggable':
      case 'contenteditable':
        if ($value!==null)
        {
          $html = ' ';
          $html .= $name;
          $html .= (!empty($value)) ? '="true"' : '="false"';
        }
        break;

      case 'autocomplete':
        if ($value!==null)
        {
          $html = ' ';
          $html .= $name;
          $html .= (!empty($value)) ? '="on"' : '="off"';
        }
        break;

      case 'translate':
        if ($value!==null)
        {
          $html = ' ';
          $html .= $name;
          $html .= (!empty($value)) ? '="yes"' : '="no"';
        }
        break;

      case 'class' and is_array($value):
        $classes = implode(' ', self::cleanClasses($value));
        if ($classes!=='')
        {
          $html = ' class="';
          $html .= htmlspecialchars($classes, ENT_QUOTES, self::$encoding);
          $html .= '"';
        }
        break;

      default:
        if ($value!==null && $value!=='')
        {
          $html = ' ';
          $html .= htmlspecialchars($name, ENT_QUOTES, self::$encoding);
          $html .= '="';
          $html .= htmlspecialchars(Cast::toManString($value), ENT_QUOTES, self::$encoding);
          $html .= '"';
        }
        break;
    }

    return $html;
  }