10 Set Levels on Roots

<..set levels for roots..>
 <dom name="." xml="." method="rootLevel" class="tex4ht.HtJsml" />
 <.remove xml declaration.>
-_-_-

<..static void rootLevel(dom)..>
 public static void rootLevel(Node d) {
    dom = (Document) d;
    setRootLevel(d.getFirstChild());
 }
 private static int setRootLevel( Node node ){
   int level = 0;
 //  String clName = null;
   if (node.hasChildNodes()) {
     <.count root levels inherited from children.>
     String ndName =  node.getNodeName();
     <.block for roots.>
     if( ndName.equals("msqrt") || ndName.equals("mroot") ){
         <.set extra levels for roots.>
         level++;
   } }
   return level;
 }
-_-_-

<..count root levels inherited from children..>
 NodeList children = node.getChildNodes();
 int max = 0;
 for (int i = 0; i < children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
     int d = setRootLevel(child);
     if( d > max ){ max = d; }
 } }
 level += max;
-_-_-

<..block for roots..>
 if( ndName.equals("msub") || ndName.equals("msup") ||
     ndName.equals("msubsup")
 ) {
    return 0;
 }
-_-_-

<..set extra levels for roots..>
 for (int i = 0; i < children.getLength(); i++) {
   Node child = children.item(i);
   if (child.getNodeType() == Node.ELEMENT_NODE) {
     Node cls = child.getAttributes()
                     .getNamedItem("class");
     if (cls != null) {
       String clsName = cls.getNodeValue();
       if( clsName.equals("begin-root")
           || clsName.equals("mid-root")
           || clsName.equals("end-root")
       ){
          insertLevelPrefix(child, level);
 } } } }
-_-_-