1 16 19 package org.apache.xalan.lib; 20 21 import org.apache.xml.dtm.ref.DTMNodeProxy; 22 23 import org.w3c.dom.Node ; 24 import org.w3c.dom.NodeList ; 25 26 30 public abstract class ExsltBase 31 { 32 38 protected static String toString(Node n) 39 { 40 if (n instanceof DTMNodeProxy) 41 return ((DTMNodeProxy)n).getStringValue(); 42 else 43 { 44 String value = n.getNodeValue(); 45 if (value == null) 46 { 47 NodeList nodelist = n.getChildNodes(); 48 StringBuffer buf = new StringBuffer (); 49 for (int i = 0; i < nodelist.getLength(); i++) 50 { 51 Node childNode = nodelist.item(i); 52 buf.append(toString(childNode)); 53 } 54 return buf.toString(); 55 } 56 else 57 return value; 58 } 59 } 60 61 68 protected static double toNumber(Node n) 69 { 70 double d = 0.0; 71 String str = toString(n); 72 try 73 { 74 d = Double.valueOf(str).doubleValue(); 75 } 76 catch (NumberFormatException e) 77 { 78 d= Double.NaN; 79 } 80 return d; 81 } 82 } 83 | Popular Tags |