String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped))
Node child = node.getFirstChild(); while (child != null)
  void strip(Node node)    throws TransformerConfigurationException  {    short nt = node.getNodeType();    if (nt == Node.ENTITY_REFERENCE_NODE)      {        // Replace entity reference with its content        Node parent = node.getParentNode();        Node child = node.getFirstChild();        if (child != null)          {            strip(child);          }        while (child != null)          {            Node next = child.getNextSibling();            node.removeChild(child);            parent.insertBefore(child, node);            child = next;          }        parent.removeChild(node);      }    if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE)      {        if (!stylesheet.isPreserved((Text) node))          {            node.getParentNode().removeChild(node);          }        else          {            String text = node.getNodeValue();            String stripped = text.trim();            if (!text.equals(stripped))              {                node.setNodeValue(stripped);              }          }      }    else      {        for (Node child = node.getFirstChild(); child != null;             child = child.getNextSibling())          {            strip(child);          }      }  }