code: public static void addAttribute(SerializationHandler handler, int attr)
          throws TransformerException
      {
  
          TransformerImpl transformer =
              (TransformerImpl) handler.getTransformer();
          DTM dtm = transformer.getXPathContext().getDTM(attr);
  
          if (SerializerUtils.isDefinedNSDecl(handler, attr, dtm))
              return;
  
          String ns = dtm.getNamespaceURI(attr);
  
          if (ns == null)
              ns = "";
  
          // %OPT% ...can I just store the node handle?
          try
          {
              handler.addAttribute(
                  ns,
                  dtm.getLocalName(attr),
                  dtm.getNodeName(attr),
                  "CDATA",
                  dtm.getNodeValue(attr), false);
          }
          catch (SAXException e)
          {
              // do something?
          }
      }
docs: Copy an DOM attribute to the created output element, executing
  attribute templates as need be, and processing the xsl:use
  attribute.
  
  @param handler SerializationHandler to which the attributes are added.
  @param attr Attribute node to add to SerializationHandler.
  
  @throws TransformerException